N
N
NyxDeveloper2021-03-13 16:22:02
Django
NyxDeveloper, 2021-03-13 16:22:02

UWSGI not running django project out of the box?

Deploying a Django project on Nginx + uWSGI. I ran into a strange error, the wsgi test file starts up normally, but the dzhang one, which comes straight from the box, does not want to start for some reason.
Here is the content of the test file:

def application(env, start_response):
     start_response('200 OK', [('Content-Type','text/html')])
     return [b"Hello World"]

Here is the junga file:
import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'testproject.settings')

application = get_wsgi_application()


traceback:
Traceback (most recent call last):
  File "wsgi.py", line 16, in <module>
    application = get_wsgi_application()
  File "/usr/local/lib/python3.6/dist-packages/django/core/wsgi.py", line 12, in get_wsgi_application
    django.setup(set_prefix=False)
  File "/usr/local/lib/python3.6/dist-packages/django/__init__.py", line 19, in setup
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  File "/usr/local/lib/python3.6/dist-packages/django/conf/__init__.py", line 82, in __getattr__
    self._setup(name)
  File "/usr/local/lib/python3.6/dist-packages/django/conf/__init__.py", line 69, in _setup
    self._wrapped = Settings(settings_module)
  File "/usr/local/lib/python3.6/dist-packages/django/conf/__init__.py", line 170, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'testproject'

I deploy the project in virtualenv, python version is 3.8.8.
I understand that it does not find the module of the project itself, but I do not know why. Help with good advice, please!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
NyxDeveloper, 2021-03-13
@NyxDeveloper

If suddenly someone has the same problem with python versions, then on ubuntu the versions are changed with the following command

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1

A
alekssamos, 2021-03-14
@alekssamos

You run not through a virtual environment, but really in a real system, and, of course, there is nothing there. You need to run something like this: .venv/bin/python myscript.py
By the way, you can also install packages on the environment like this: .venv/bin/pip install django
But this is for the normal launch of one command without activating the environment.
As for the server, try reading this:
Nginx + uWSGI + virtualenv + Django | Recipes | DJ...

D
Dr. Bacon, 2021-03-13
@bacon

UWSGI runs a django project out of the box. And now see what python you have in traceback.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question