Как задеплоить django?

Всем здравствуйте, я первый раз выкладываю django проект на хостинг и столкнулся с такой неприятностью:

[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, django 1.7.1
Я пробовал запускать runserver ошибки не выдал

я попробовал поставить в USE_I18N = False и USE_L10N = False, после этого стал вываливаться django debug с ошибкой Models aren't loaded yet.
Может кто сталкивался?
  • Вопрос задан
  • 3459 просмотров
Решения вопроса 1
alxpy
@alxpy
Тут детально все рассписано, надеюсь Вам поможет - alxpy.com/django-uwsgi-nginx
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 2
ali_aliev
@ali_aliev
Разработчик на Django/Python, JavaScript
где конфиги? почему не связка nginx + uwsgi + supervisor? по моему тут проще некуда.

Ставим uwsgi: sudo pip install uwsgi
Ставим supervisor: sudo apt-get install supervisor

создаем .env в директории в корне проекта командой: virtualenv .env
source .env/bin/activate

ставим зависимости вашего проекта
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/;
    }
}


перезагружаемся: sudo /etc/init.d/nginx/restart
sudo supervisorctl reload
sudo supervisorctl restart yoursite
Ответ написан
GrossFinger
@GrossFinger
Довольно много статей на эту тему. В основном (из того, что мне попадалось) используется связка Nginx & Gunicorn +допустим, Fabric Мне больше нравится Nginx & uWSGI. По ключевым словам "django nginx uwsgi" ты сможешь найти очень много годного материала. Для быстрого выкладывания сорцов, выполнение команд migrate, collectstatic и пр подобных операций можешь использовать Fabric. Вот, мой пример того, чем я пользовался год-полтора назад: https://pastebin.com/iWM1v449 - возможно, он тебе поможет.

PS: обрати внимание на Docker
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы