django - 服务器错误加载静态文件 [英] django - Server error loading static files

查看:108
本文介绍了django - 服务器错误加载静态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我建立我自己的django网站。现在我加载了静态卡。
在控制台中得到以下错误:

So im building my own django site. Right now im stuck with loading the statics. im getting the following error in the console:

 GET http://localhost:8000/static/css/style.css 500 (Internal Server Error)

我试图使用静态标签加载一个css文件:

Im trying to load a css file using the static taggs:

{{ STATIC_URL }}

在我的设置中,我编辑了以下内容:

in my settings i've edited the following:

PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))

STATIC_ROOT = os.environ.get('STATIC_ROOT',os.path.join(PROJECT_ROOT,"static",))
STATIC_URL = '/static/'


STATICFILES_DIRS = (
os.path.join(PROJECT_ROOT, "static",),
)

还添加了TEMPLATE_CONTEXT_PROCESSORS:

also added the TEMPLATE_CONTEXT_PROCESSORS:

TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
)

将以下内容添加到urls.py中,以便我可以导航到localhost:8000 / static /

added the following to urls.py so i can navigate to localhost:8000/static/

urlpatterns += patterns('',
(r'^static/(?P<path>.*)$',
'django.views.static.serve',
{'document_root': settings.STATIC_ROOT}),
)



I'm not sute what im doing wrong. The PROJECT_ROOT is directing to the root of the project. I'm also using that for my TEMPLATE_DIR, and that works fine.

希望有人可以启发我!我一直在搜索,看着其他的问题,但是据我所见,我做了一切我应该做的事情!

Hopefully someone can enlighten me! I've been googling around, and looked at other questions, but as far as i can see, i did everything how i'm supposed to!

提前Thx! !

推荐答案

Change the your debug into DEBUG=False

这篇关于django - 服务器错误加载静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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