I'm new to Django. Trying to get my app running under Nginx+gunicorn but running into a few issues. If someone has some insight, I'd appreciate it. I've found a few things to try on google, but gunicorn still seems hosed.
1) I've rsync'd my Django project from my dev box to the Nginx host. If I try launch using the dev server, it doesn't work unless I use Python 3. What have I got messed up?
I've googled the ...from exec
error below and found I could get it working if prefixed with python3
. Seems like a workaround for a larger issue though since this way of starting it isn't mentioned in any of the tutorials I've been following.
This bombs:
(venv) $ python manage.py runserver 127.0.0.1:8777
File "manage.py", line 16
) from exc
^
SyntaxError: invalid syntax
This works:
(venv) $ python3 manage.py runserver 127.0.0.1:8777
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
November 22, 2019 - 15:46:59
Django version 2.2.7, using settings 'auth.settings'
Starting development server at http://127.0.0.1:8777/
Quit the server with CONTROL-C.
[22/Nov/2019 15:47:27] "GET /accounts/login/ HTTP/1.0" 200 1229
^C(venv) $
2) Above, I can run the app fine over Nginx if using the dev server. If executed via gunicorn
however, things fall apart. How come? Python says it cannot import name path
but it seems to run fine from the dev server (the login page also comes up in the browser correctly) so I'm kinda lost as to what the issue is.
(venv) $ gunicorn --bind 127.0.0.1:8777 auth.wsgi
[2019-11-22 09:43:45 +0000] [2239] [INFO] Starting gunicorn 19.7.1
[2019-11-22 09:43:45 +0000] [2239] [INFO] Listening at: http://127.0.0.1:8777 (2239)
[2019-11-22 09:43:45 +0000] [2239] [INFO] Using worker: sync
[2019-11-22 09:43:45 +0000] [2243] [INFO] Booting worker with pid: 2243
Internal Server Error: /accounts/login/
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py", line 172, in _get_response
resolver_match = resolver.resolve(request.path_info)
File "/usr/lib/python2.7/dist-packages/django/urls/resolvers.py", line 364, in resolve
for pattern in self.url_patterns:
File "/usr/lib/python2.7/dist-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/lib/python2.7/dist-packages/django/urls/resolvers.py", line 407, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/lib/python2.7/dist-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/lib/python2.7/dist-packages/django/urls/resolvers.py", line 400, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/var/www/django/auth2/auth/urls.py", line 17, in <module>
from django.urls import path, include
ImportError: cannot import name path
[2019-11-22 09:43:58 +0000] [2239] [INFO] Handling signal: winch
[2019-11-22 09:43:58 +0000] [2239] [INFO] Handling signal: winch
^C[2019-11-22 09:45:06 +0000] [2239] [INFO] Handling signal: int
[2019-11-22 15:45:06 +0000] [2243] [INFO] Worker exiting (pid: 2243)
[2019-11-22 09:45:06 +0000] [2239] [INFO] Shutting down: Master
(venv) $ pip freeze
asn1crypto==0.24.0
backports.os==0.1.1
configparser==4.0.2
contextlib2==0.6.0.post1
cryptography==2.1.4
Django==1.11.26
enum34==1.1.6
future==0.18.2
gunicorn==19.9.0
idna==2.6
importlib-metadata==0.23
ipaddress==1.0.17
keyring==10.6.0
keyrings.alt==3.0
more-itertools==5.0.0
path.py==11.5.2
pathlib2==2.3.5
psycopg2-binary==2.8.4
pycrypto==2.6.1
pygobject==3.26.1
python-apt==1.6.4
pytz==2019.3
pyxdg==0.25
scandir==1.10.0
SecretStorage==2.3.1
six==1.13.0
sqlparse==0.2.4
zipp==0.6.0
(venv) $