我有一个Django应用程序,它呈现一些网页,让人们向我的数据库提交一些信息。 项目结构如下:
--wun/ --manage.py --templates/uploader/ --some_html_files.html --static/uploader/ --css_files.css --wun/ --settings.py --urls.py --wsgi.py --uploader/ --app_files.py所以这个项目被称为'wun' ,我的应用被称为'uploader' 。 结构是典型的Django。
在Django的开发服务器上本地运行它没有问题,但是当它部署到GAE时,我在每个访问的URL端点上都404 Not Found 。 我在Django设置中打开了DBUG ,但没有其他信息。 我可以在GAE的日志中看到端点被访问过。
我想也许GAE找不到静态文件和模板? 我在Django中有以下设置:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [BASE_DIR,os.path.join(BASE_DIR, 'templates')], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] STATIC_URL = '/static/'在App Engine上:
handlers: - url: /static static_dir: static - url: /static/uploader static_dir: /static/uploader - url: .* script: wun.wsgi.application但我不认为前两个网址是在这里使用的,因为我不直接提供网页。 所有页面都是由模板中的Django视图呈现的。
I have a Django app that renders some web pages to let people submit some information to my database. The project structure is like:
--wun/ --manage.py --templates/uploader/ --some_html_files.html --static/uploader/ --css_files.css --wun/ --settings.py --urls.py --wsgi.py --uploader/ --app_files.pySo the project is called 'wun' and my app is called 'uploader'. The structure is typical Django.
There's no issue running it on Django's development server locally, but when deployed it to GAE, I get 404 Not Found on every url endpoint I visit. I turned the DBUG on in Django settings but there's not other information. I can see the endpoints been visited on GAE's log.
I think maybe GAE cannot find the static files and templates? I have the following settings in Django:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [BASE_DIR,os.path.join(BASE_DIR, 'templates')], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] STATIC_URL = '/static/'On App Engine:
handlers: - url: /static static_dir: static - url: /static/uploader static_dir: /static/uploader - url: .* script: wun.wsgi.applicationBut I don't think the first two urls are used here, since I don't serve pages directly. All pages are rendered by Django views from templates.
最满意答案
事实证明,GoogleAppEngineLauncher会在我的项目文件夹下自动创建另一个文件夹,并且它正在使用那里没有任何内容的应用程序设置。 所以当访问服务器时,实际上没有运行Django应用程序,它只是一个空的服务器。
It turns out that GoogleAppEngineLauncher automatically created another folder under my project folder, and it is using the app settings there which has nothing. So when the server was visited, there was actually no Django app running, it is just an empty server.
更多推荐
发布评论