I
I
IvanOne2014-12-20 20:14:35
Django
IvanOne, 2014-12-20 20:14:35

How to deploy django?

Hello everyone, this is my first time posting a django project for hosting and I ran into such a nuisance:

[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27] mod_wsgi (pid=579): Exception occurred processing WSGI script '/opt/repo/ROOT/application'.
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27] Traceback (most recent call last):
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]   File "/opt/repo/virtenv/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]     response = self.get_response(request)
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]   File "/opt/repo/virtenv/lib/python2.7/site-packages/django/core/handlers/base.py", line 199, in get_response
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]     response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]   File "/opt/repo/virtenv/lib/python2.7/site-packages/django/core/handlers/base.py", line 236, in handle_uncaught_exception
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]     return debug.technical_500_response(request, *exc_info)
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]   File "/opt/repo/virtenv/lib/python2.7/site-packages/django/views/debug.py", line 91, in technical_500_response
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]     html = reporter.get_traceback_html()
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]   File "/opt/repo/virtenv/lib/python2.7/site-packages/django/views/debug.py", line 350, in get_traceback_html
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]     return t.render(c)
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]   File "/opt/repo/virtenv/lib/python2.7/site-packages/django/template/base.py", line 148, in render
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]     return self._render(context)
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]   File "/opt/repo/virtenv/lib/python2.7/site-packages/django/template/base.py", line 142, in _render
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]     return self.nodelist.render(context)
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]   File "/opt/repo/virtenv/lib/python2.7/site-packages/django/template/base.py", line 844, in render
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]     bit = self.render_node(node, context)
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]   File "/opt/repo/virtenv/lib/python2.7/site-packages/django/template/debug.py", line 80, in render_node
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]     return node.render(context)
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]   File "/opt/repo/virtenv/lib/python2.7/site-packages/django/template/debug.py", line 90, in render
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]     output = self.filter_expression.resolve(context)
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]   File "/opt/repo/virtenv/lib/python2.7/site-packages/django/template/base.py", line 624, in resolve
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]     new_obj = func(obj, *arg_vals)
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]   File "/opt/repo/virtenv/lib/python2.7/site-packages/django/template/defaultfilters.py", line 769, in date
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]     return format(value, arg)
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]   File "/opt/repo/virtenv/lib/python2.7/site-packages/django/utils/dateformat.py", line 343, in format
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]     return df.format(format_string)
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]   File "/opt/repo/virtenv/lib/python2.7/site-packages/django/utils/dateformat.py", line 35, in format
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]     pieces.append(force_text(getattr(self, piece)()))
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]   File "/opt/repo/virtenv/lib/python2.7/site-packages/django/utils/dateformat.py", line 268, in r
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]     return self.format('D, j M Y H:i:s O')
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]   File "/opt/repo/virtenv/lib/python2.7/site-packages/django/utils/dateformat.py", line 35, in format
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]     pieces.append(force_text(getattr(self, piece)()))
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]   File "/opt/repo/virtenv/lib/python2.7/site-packages/django/utils/encoding.py", line 85, in force_text
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]     s = six.text_type(s)
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]   File "/opt/repo/virtenv/lib/python2.7/site-packages/django/utils/functional.py", line 144, in __text_cast
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]     return func(*self.__args, **self.__kw)
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]   File "/opt/repo/virtenv/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 83, in ugettext
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]     return _trans.ugettext(message)
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]   File "/opt/repo/virtenv/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 325, in ugettext
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]     return do_translate(message, 'ugettext')
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]   File "/opt/repo/virtenv/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 306, in do_translate
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]     _default = translation(settings.LANGUAGE_CODE)
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]   File "/opt/repo/virtenv/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 209, in translation
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]     default_translation = _fetch(settings.LANGUAGE_CODE)
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]   File "/opt/repo/virtenv/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 189, in _fetch
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27]     "The translation infrastructure cannot be initialized before the "
[Sat Dec 20 16:43:15 2014] [error] [client 178.141.172.27] AppRegistryNotReady: The translation infrastructure cannot be initialized before the apps registry is ready. Check that you don't make non-lazy gettext calls at import time.

Apache server, django 1.7.1
I tried to run runserver, I didn't get any errors,
I tried to set USE_I18N = False and USE_L10N = False, after that django debug started to fall out with the error Models aren't loaded yet.
Can anyone come across?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
alxpy, 2015-01-22
@IvanOne

Everything is detailed here, I hope it will help you - alxpy.com/django-uwsgi-nginx

A
Ali Aliyev, 2014-12-20
@ali_aliev

where are the configs? why not a bunch of nginx + uwsgi + supervisor? In my opinion, there is nowhere easier.
Install uwsgi: sudo pip install uwsgi
Install supervisor: sudo apt-get install supervisor
create .env in a directory at the root of the project with the command: virtualenv .env
source .env/bin/activate install
your project dependencies
pip install -r requirements.txt
File: / etc/supervisor/conf.d/yoursite.conf

[program:yoursite]
command=uwsgi --ini /etc/uwsgi.ini
autostart=true
autorestart=true
stderr_logfile = /tmp/uwsgi-err.log
stdout_logfile = /tmp/uwsgi.log

File: /etc/uwsgi.ini
[uwsgi]
chdir           = /home/projectroot
wsgi-file          = /home/projectroot/wsgi.py
home            = /home/projectroot/.env
logto           = /var/log/uwsgi.log

master          = true
processes       = 10
socket          = /tmp/yoursite.sock
vacuum          = true
touch-reload    = /tmp/yoursite.reload

File: /etc/nginx/sites-enabled/yoursite.conf
server {
    listen   80;
    server_name  yoursite.com;
    access_log  /home/var/log/nginx/yoursite.nginx.access.log;
    error_log  /home/var/log/nginx/yoursite.nginx.error.log;

    location / {
        uwsgi_pass   unix:///tmp/yoursite.sock;
        include uwsgi_params;
    }
    location /static/ {
        alias /home/yoursite/assets/;
    }
}

reboot: sudo /etc/init.d/nginx/restart
sudo supervisorctl reload
sudo supervisorctl restart yoursite

F
Finger Gross, 2017-11-05
@GrossFinger

There are quite a few articles on this subject. Basically (from what I came across) a bunch of Nginx & Gunicorn + let's say Fabric is used. I like Nginx & uWSGI more. By the keywords "django nginx uwsgi" you can find a lot of good stuff. To quickly lay out sorts, execute commands like migrate, collectstatic and other similar operations, you can use Fabric. Here is my example of what I used a year and a half ago: https://pastebin.com/iWM1v449 - maybe it will help you.
PS: pay attention to Docker

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question