关于GAE的Django:资源无法找到(Django on GAE: Resource could not be found)

编程入门 行业动态 更新时间:2024-10-27 10:18:57
关于GAE的Django:资源无法找到(Django on GAE: Resource could not be found)

我有一个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.py

So 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.application

But 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.

更多推荐

本文发布于:2023-08-05 06:17:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1428764.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:资源   GAE   Django   Resource

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!