在GAE上使用Django:找不到资源 [英] Django on GAE: Resource could not be found

查看:64
本文介绍了在GAE上使用Django:找不到资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

因此该项目称为'wun',而我的应用程序称为'uploader'.结构是典型的Django.

So the project is called 'wun' and my app is called 'uploader'. The structure is typical Django.

在本地的Django开发服务器上运行它没有问题,但是当将其部署到GAE时,我访问的每个URL端点都会得到404 Not Found.我在Django设置中打开了DBUG,但是没有其他信息.我可以在GAE的日志中看到已访问端点.

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.

我认为也许GAE无法找到静态文件和模板?我在Django中具有以下设置:

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/'

在App Engine上:

On App Engine:

handlers:
- url: /static
  static_dir: static
- url: /static/uploader
   static_dir: /static/uploader
- url: .*
  script: wun.wsgi.application

但是我不认为这里使用前两个URL,因为我不直接提供页面.所有页面均由Django视图通过模板呈现.

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.

这篇关于在GAE上使用Django:找不到资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆