开发者

Django & static files while Debug mode is ON

i have some trouble with static files (images) in templates while Debug is set to True: images are not showed. here is the code of some settings and templates: http://dpaste.com/594183/开发者_C百科

with these settings, the printed html doesn't contain the right path to static files. In any case i remember some time ago that even with the right path images are not showed, so maybe the problem is not the path.

thanks, Luke


Where do you put your static files? In a new Django, you should keep them inside your app, e.g. if you have an app named 'blog', create a directory blog/static and put your files there. Debug server (manage.py runserver) will serve them at localhost/static/.


The first thing that comes to mind looking at your paste is that there is a space being inserted into your paths. In the urls for the background images of your css, there is a space between the context variable STATIC_URL and the hardcoded path. Be careful about spaces in django, it's template engine can get very tetchy about them and often won't clean them up for you. One such situation is {{ value|length }}, where the value won't be correctly parsed to it's length if you insert spaces around the pipe; This makes sense, since spaces separate arguments. Either remedy this by removing the space in your CSS's Url or use the more flexible {% static "filename.png" %} template tag instead.

Check out https://docs.djangoproject.com/en/dev/howto/static-files/ for more explanation.

It's also worth noting that when you run the system outside debug mode that the static files will not be managed for you. In production you are responsible for managing your static files yourself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜