I try to deploy nginx+uwsgi+django.
In .ini-file is required to set module=mysite.wsgi.
But in my project directory there is no any .wsgi-file.
Project created by
django-admin.py startproject xproj
Why it is possible?
in Django 1.4.0 and above wsgi.py exist under xproj->xproj folder .
Django provided wsgi.py t interact with web server .
Actually wsgi.py is the file you want. As you can see here.
You see in Python people often use the Python module syntax when talking about files. So for example if you are talking about your models[.]py in a module named "Users" you wouldn't say users/models[.]py you would say users.models. This is what the gunicorn docs are doing. The writer of the docs is talking about the file myproject/wsgi[.]py but is using the module syntax of myproject.wsgi.
Related
I have a Django project with 2 apps. I want to use the Notion API in one of the apps, so I have to install it's NPM module. However, I have never use NPM nor a bundler (I understand I have to use one for the import statement).
I have no idea on how to do it. Where should I install the module? Should I install Webpack or something similar? How can I integrate both of this technologies with Django?
Can someone please explain this to me, or reffer to an article/video explaining?
I have been trying for hours now and I can't find anything detailed.
I have checked the following links:
Django how to use npm modules with static/ templates
https://gist.github.com/brizandrew/685a588fbefbd64cd95ed9ec4db84848
https://www.saaspegasus.com/guides/modern-javascript-for-django-developers/integrating-javascript-pipeline/
https://www.saaspegasus.com/guides/modern-javascript-for-django-developers/integrating-javascript-pipeline/
https://www.techiediaries.com/django-webpack-react/
https://owais.lone.pw/blog/webpack-plus-reactjs-and-django/
https://pythonrepo.com/repo/owais-django-webpack-loader-python-developing-restful-apis
And a lot more.
They either don't have what I need (they are for react), or I can just not understand them. I know there are probably a lot of articles on this, but either I just can't find them, or they are too complicated for me (sorry I'm dumb).
If anyone can help me, it would make my day.
Thanks!
P.S. I am using Typescript, but I can use vanilla JS if necessary.
You have two things to do in order to get your app working the way you want.
Install, configure, and run a module bundler
Use collectstatic
Module bundler:
You have a few choices, but most use webpack because it is the most popular. I prefer rollup but it is all up to preference.
rollup quickstart: https://rollupjs.org/guide/en/#quick-start
webpack: https://webpack.js.org/concepts/
Since you are using Typescript, see the plugins for bundling Typescript
https://webpack.js.org/guides/typescript/
https://github.com/rollup/rollup-plugin-typescript
After you bundle, you should have a main.js file or equivalent. Make sure that main.js is in its own folder. Bundlers will typically do this for you.
Add that directory to your STATICFILES_DIRS in settings.py.
Note that you will need to set a STATIC_ROOT for this to work. This will be a folder that you will store your collected static files at.
Run python manage.py collectstatic
Sidenote: if you are using python manage.py runserver to start your application, you don't need to run collectstatic
For those looking for a -workaround solution- this should be great
I found this website that provides you with the bundles to imported in your static files (.html)
So, for my case I needed to download Chart.js latest version's bundle and I found it available here
https://cdnjs.com/libraries/Chart.js
and add it to your html like so:
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.8.0/chart.min.js" integrity="sha512-sW/w8s4RWTdFFSduOTGtk4isV1+190E/GghVffMA9XczdJ2MDzSzLEubKAs5h0wzgSJOQTRYyaz73L3d6RtJSg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
Like in python i install a package using
pip install django
inside a virtualenv,
Then it puts all the files in site-packages folder. and then i can import the package using
from django.core import mail
But i can easily browse the code of django/core in site-packages
Similarly if I install a package using npm can i see the source of that
Eg:
import React, { useEffect } from "react";
Now i want to see the react file and go through the React and useEffect
Is it possible
I do not have background in Python. So, can't explain or compare in Python way. But, yes! You can read or go through the source code in most of the cases.
Now, talking about the specific example you mentioned in question - React. Things are little complicated as we're talking about one of the popular library. You may wouldn't find React.js or react.js file directly. But, that doesn't mean you can read the source code. Let's do it.
Create an application that has react as dependency (You can create an application using create-react-app).
In this application, you'll have node_modules folder. Within this node_modules, you'll have folder after the name of dependency e.g. react. Go inside this folder.
You'll find the package.json file. Open it and look for main. The main is an entry point of the program/package. It mentioned index.js. So, let's open the index.js file.
If you open the index.js, you'll see that based on environment, they're requiring the react.production.min.js or react.development.js file. Open this react.development.js file from cjs folder.
In this file, do a search for useEffect. You will find a function with the same name.
But, I wouldn't recommended you to read the code in this way, if you're planning for React. You may try this solution. Also, if you're planning to read the source code as starting point, why not start with simple and easy to read packages? And don't forget that if not all then most of the packages are there on GitHub and on NPM website, you'll see the link for the Repository.
I am writing a Google App Engine Django REST Framework project that uses external libraries through requirements.txt.
In one of the of files in a module installed in requirements.txt, I am manually editing some code there. How do I get GAP to use this modified version instead of original one.
The way I am doing this is installing the packages in a folder called lib, modifying the package inside it and then creating a file called appengine_config.py which contains this:
from google.appengine.ext import vendor
vendor.add('lib')
But when I deploy it, it still uses the original package in requirements.txt. Any idea how to make this work?
GAE will use requirements.txt and install those libraries in the lib folder when you deploy. That is just how it works.
Nothing prevents you from deploying code outside the lib folder. You can structure your project like this:
GAE_folder:
-- app.yaml
-- requirements.txt
-- lib
-- my_app
-- my_custom_lib
I need to put this node.js module into Alloy project. It's a Facebook SDK node module.
I put the install command, and a node_module folder appear into my project folder, but I can't use it.
Where have I to put this node_module folder? Why the requires into facebook.js are not founded by the compiler?
Please, can anyone help me?
Titanium is not a pure NodeJS environment. When you use require('test') in a Titanium Alloy project, it will look for a file named test.js in the directory <Your project>/app/lib/.
Titanium can't handle a require on a directory with a package.json.
So if you want a pure NodeJS module, you'll have to put every files needed in the <Your project>/app/lib/ directory.
But keep in mind that you can't use a NodeJS module which depends on NodeJS API like requests, because there's no such things in Titanium (you have to Ti.HttpClient instead).
I am working on this question
and the only answer that worked for me is the one by alexjamesbrown (scroll down).
I could create an exe with battoexeconverter with a test node.js project.
But my real project uses several node_modules. How can I include these modules?
( I couldn't find an option to include directories. I just found the option to include files.
There are about 500 files in the required node modules and I don't want to manually include them one by one.)
You could zip/rar the folder (node_modules.zip) and use a command-line utility to unzip it at runtime (BATTOEXE stores your files in the %TEMP% directory an deletes them when the app has been quit/stopped/ended).
I wrote a tutorial blog post on this here:
http://www.alexjamesbrown.com/blog/development/create-a-standalone-exe-to-run-a-node-js-application/