【发布时间】:2012-08-25 14:38:21
【问题描述】:
当我尝试在 webfacional 的服务器上运行 webapp 时,我遇到了一个关于 STATIC_URL 和 STATIC_ROOT 的问题。
当我加载网页时,所有请求都运行良好,除了任何带有 {{ STATIC_URL}} 的链接正在运行或正在加载。
所以在firebug上出现的一个常见错误是:
GET http://mydomain/static/extras/h5bp/js/libs/modernizr-2.5.3.min.js 500 (Internal Server Error)
我的设置是:
urls.py 我什么都没做,静态文件也没有。
settings.py 调试 = 假
STATIC_ROOT = '/home/mydomain/webapps/static_app/'
STATIC_URL = 'http://mydomain/static/'
STATICFILES_DIRS = ()
views.py 查看示例
@csrf_exempt
def IndexView(request):
try:
request.user.is_authenticated()
except AttributeError:
return render_to_response('index.html',
{'request': request,},
context_instance=RequestContext(request))
return render_to_response('index.html',
{'request': request, 'profile' : request.user},
context_instance=RequestContext(request))
index.html 部分代码未找到
<script src="{{ STATIC_URL }}extras/h5bp/js/libs/modernizr-2.5.3.min.js"></script>
好吧,我遵循以下所有要点: https://docs.djangoproject.com/en/1.4/howto/static-files/ 这是另一个: http://docs.webfaction.com/software/django/getting-started.html
我正在使用正确安装的应用程序、中间件、template_contexts。
如果我遗漏了什么,请帮我弄清楚。
提前致谢!
--编辑
我不得不说,如果我只是改变 DEBUG = True 就可以了。
因为在 urls.py 我有这段代码:
if settings.DEBUG:
# static files (images, css, javascript, etc.)
urlpatterns += patterns('',
(r'^media/(?P<path>.*)/$', 'django.views.static.serve', {
'document_root': settings.MEDIA_ROOT}))
【问题讨论】:
标签: django url deployment django-staticfiles webfaction