[英]Serving Static files - Django-nonrel in Appengine
I've successfully got a basic Django-nonrel app up and running on Appengine. 我已经成功建立了一个基本的Django-nonrel应用程序,并在Appengine上运行。 The templates are getting rendered properly, but the static content returns a 404 response.
模板已正确呈现,但是静态内容返回404响应。
There is no problem with the static content in the dev server launched using `python manage.py runserver'. 使用python manage.py runserver启动的开发服务器中的静态内容没有问题。
These are the relevant lines in static.py
: 这些是
static.py
中的相关行:
STATIC_URL = '/static/'
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder', # Refers to PROJECT_DIR/static
'django.contrib.staticfiles.finders.AppDirectoriesFinder', # Appname/static
)
STATICFILES_DIRS = (os.path.join(PROJECT_DIR, 'static'),)
In the relevant template: 在相关模板中:
{% extends "base.html" %}
{% load staticfiles %}
{% block title %}Adding Objects{% endblock %}
{% block content %}
<p>Placeholder for Objects</p>
<img src="{% static "test_pattern.gif" %}">
<img src="{% static "sample_overlay.gif" %}">
{% endblock %}
With this, static files in myproject/static
directory and myproject/myapp/static
directory are being served successfully in the dev server ( python manage.py runserver
). 这样,可以在开发服务器(
python manage.py runserver
)中成功提供myproject/static
目录和myproject/myapp/static
目录中的myproject/myapp/static
文件。
This is my app.yaml
: 这是我的
app.yaml
:
application: appname
version: 1
runtime: python27
api_version: 1
threadsafe: yes
builtins:
- remote_api: on
inbound_services:
- warmup
libraries:
- name: django
version: latest
handlers:
- url: /_ah/queue/deferred
script: djangoappengine.deferred.handler.application
login: admin
- url: /_ah/stats/.*
script: djangoappengine.appstats.application
- url: /media/admin
static_dir: django/contrib/admin/media
expiration: '0'
- url: /.*
script: djangoappengine.main.application
Any clue how to fix this? 任何线索如何解决这个问题? I don't want the Appengine web server to handle static files , I want to route everything through Django (at least for now).
我不希望Appengine网络服务器处理静态文件 ,我希望通过Django路由所有文件 (至少目前如此)。 Hence a solution like this isn't really acceptable in my case.
因此,就我而言, 这种解决方案实际上是不可接受的。
EDIT: I can easily get around this with this in my app.yaml
and serving all static files from projectdir/static
. 编辑:我可以在我的
app.yaml
轻松解决此问题,并从projectdir/static
提供所有静态文件。
- url: /static
static_dir: static
But this solution seems dirty, I'd like to leave it all to Django. 但是这个解决方案似乎很肮脏,我想将其全部留给Django。
Your adding the /static mapping in app.yaml is the correct method. 您在app.yaml中添加/ static映射是正确的方法。 It is not "dirty".
这不是“肮脏”。
Also, you are adding the django library in app.yaml. 另外,您还要在app.yaml中添加django库。 That is not correct.
那是不对的。 Django-nonrel uses its own branch of Django, which you should import as a directory with your app.
Django-nonrel使用自己的Django分支,您应该将其作为应用程序的目录导入。 Adding the django call to libraries in app.yaml means you are importing 2 versions of Django, which can cause strange errors.
将django调用添加到app.yaml中的库意味着您要导入2个版本的Django,这可能会导致奇怪的错误。 Delete the Django library call in app.yaml, and import the Django version that is included with nonrel.
删除app.yaml中的Django库调用,然后导入nonrel随附的Django版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.