Django: GET css returns 404?

无人久伴 提交于 2019-12-04 14:59:58

There are a number of things you need to do in order to get the static urls working on the development platform.

For this i would recommend looking through and reading this link. https://docs.djangoproject.com/en/dev/howto/static-files/

As well as this you also need to return a request context from your view.

Note that within your urls.py file you will also need to add the line.

urlpatterns += staticfiles_urlpatterns()

This line allows the URL's module within a development server to serve static files.

I also notice that you have a variable within your os.path.join code. os.path.join will already be pointing at you development directory if you are using a basic django setup.

You should be able to use:

# Additional locations of static files
STATICFILES_DIRS = (
    os.path.join('static'),
)

Note: Also make sure your views are a returning a request context, as this is required for the STATIC_URL variable to be populated. Likewise, ensure you have all the TEMPLATE_CONTEXT_PROCESSORS added into the settings.py file

YeisonVargas

The solution is:

{% load static from staticfiles %}
<link rel="Stylesheet" type="text/css" href="{% static "css.css" %}"/>

This is a correct way for call static files on Django 1.7.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!