【问题标题】:uwsgi error : Requested setting DEBUG, but settings are not configureduwsgi 错误:请求设置 DEBUG,但未配置设置
【发布时间】:2014-02-13 10:32:18
【问题描述】:

您好,我正在尝试在 Amazon EC2 上设置 nginx+uwsgi+django,参考本教程http://www.yaconiello.com/blog/setting-aws-ec2-instance-nginx-django-uwsgi-and-mysql/#sthash.g42ylQcA.MJX0ZbDz.dpbs ,

但是得到了低于uwsgi的错误,

错误日志

*** Operational MODE: single process ***
added /home/ubuntu/web/lightea.com/ to pythonpath.
Traceback (most recent call last):
  File "/home/ubuntu/web/lightea.com/wsgi.py", line 1, in <module>
    import os, sys, site, django.core.handlers.wsgi
  File "/home/ubuntu/web/lightea.com/venv/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 11, in <module>
    from django.core.handlers import base
  File "/home/ubuntu/web/lightea.com/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 12, in <module>
    from django.db import connections, transaction
  File "/home/ubuntu/web/lightea.com/venv/local/lib/python2.7/site-packages/django/db/__init__.py", line 83, in <module>
    signals.request_started.connect(reset_queries)
  File "/home/ubuntu/web/lightea.com/venv/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 88, in connect
    if settings.DEBUG:
  File "/home/ubuntu/web/lightea.com/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
    self._setup(name)
  File "/home/ubuntu/web/lightea.com/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 47, in _setup
    % (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***

/home/ubuntu/web/lightea.com/wsgi.py

import os, sys, site, django.core.handlers.wsgi

SITE_DIR = '/home/ubuntu/web/lightea.com/elderlytracking/django_test/'
site.addsitedir(SITE_DIR)
sys.path.append(SITE_DIR)

os.environ['DJANGO_SETTINGS_MODULE'] = 'django_test.settings'
application = django.core.handlers.wsgi.WSGIHandler()

setting.py 位于 /home/ubuntu/web/lightea.com/elderlytracking/django_test/django_test 文件夹中。

【问题讨论】:

    标签: python django nginx amazon-ec2 uwsgi


    【解决方案1】:

    试试这个:

    import os
    import sys
    
    sys.path.append('/home/ubuntu/web/lightea.com/elderlytracking/django_test')
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_test.settings") # here django_test is a directory within django_test project 
    
    from django.core.wsgi import get_wsgi_application
    application = get_wsgi_application()
    

    【讨论】:

      猜你喜欢
      • 2020-09-27
      • 2017-10-21
      • 2018-05-21
      • 2020-04-12
      • 2013-03-22
      • 2018-10-09
      • 2015-04-16
      • 2021-08-07
      • 1970-01-01
      相关资源
      最近更新 更多