2011-02-25 51 views
3

因此,我正在學習如何使用Django並使用Google App Engine。我在我的主目錄下有最新的Django目錄。Django + GoogleAppEngine錯誤:DJANGO_SETTINGS_MODULE未定義

當我從本地運行它時,它工作正常。但是,當我部署它並從網頁運行它時,我收到了服務器錯誤。

這裏是我的main.py代碼和settings.py

main.py:

import os 
import settings 
from django.template import Context, Template 
from google.appengine.ext import webapp 
from google.appengine.ext.webapp.util import run_wsgi_app 

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' 

class MainPage(webapp.RequestHandler): 
    def get(self): 
     self.response.headers['Content-Type'] = 'text/plain' 
     self.response.out.write('Hello, World!\n') 
     t = Template('It is now {% now "jS F Y H:i" %}') 
     c = Context({ }) 
     self.response.out.write(t.render(c)) 

application = webapp.WSGIApplication(
            [('/', MainPage)], 
            debug=True) 

def main(): 
    run_wsgi_app(application) 

if __name__ == "__main__": 
    main() 

settings.py:

import os 

DEBUG = True 
TEMPLATE_DEBUG = DEBUG 
TIME_ZONE = 'America/Whitehorse' 
LANGUAGE_CODE = 'en-us' 
SITE_ID = 1 
+0

無論何時刷新內存緩存,我都會收到此錯誤。 – abel 2012-11-13 07:08:57

回答

2

如果您有麻煩環境變量,然後嘗試直接配置設置(請參閱http://docs.djangoproject.com/en/dev/topics/settings/#using-settings-without-setting-django-settings-module

import settings 
import django.conf 

# Filter out all the non-setting attributes of the settings module 
settingsKeys = filter(lambda name: str(name) == str(name).upper(), 
         dir(settings)) 

# copy all the setting values from the settings module into a dictionary 
settingsDict = dict(map(lambda name: (name, getattr(settings, name)), 
         settingsKeys)) 

django.conf.settings.configure(**settingsDict)