Django 1.10.2 manage.py runserver Not Found:/" /static/index.css"

时间:2016-10-30 20:50:44

标签: html django templates

我可能犯了一个简单的错误,但经过几天的故障排除和迭代后,我无法找到问题的根源。尽管我尽了最大的努力,但Django拒绝加载我的静态css文件,但每次加载html并吐出完全相同的错误。错误是int main(int, char**) 这是我当前的代码:

APP_NAME / APP_NAME /模板/ index.html中

Not Found: /"/static/index.css"

APP_NAME / urls.py

    {% load staticfiles %}
    <link rel="stylesheet" type="text/css" href=“{% static 'index.css' %}”>

APP_NAME / APP_NAME / urls.py

    from django.conf.urls import url
    from django.contrib import admin
    from django.conf import settings
    from django.conf.urls.static import static

    urlpatterns = [
        url(r'^APP_NAME/', include("APP_NAME.urls")),
        url(r'^admin/', admin.site.urls),
    ] + static(settings.STATIC_URL, document_root = settings.STATIC_ROOT)

APP_NAME / APP_NAME / settings.py

    from django.conf.urls import url
    from django.conf import settings
    from django.conf.urls.static import static

    from . import views

    urlpatterns = [
            url(r"^$", views.index, name = "index"),
    ] + static(settings.STATIC_URL, document_root = settings.STATIC_ROOT)

2 个答案:

答案 0 :(得分:1)

您不需要添加静态网址 - 如果DEBUG = True,django会搜索并为您提供静态文件。试试

findstatic index --verbosity=2

查看实际搜索静态文件的位置。正如Django STATIC_URL only works without leading slash

所建议的那样

答案 1 :(得分:1)

您的报价类型错误

<link rel="stylesheet" type="text/css" href=“{% static 'index.css' %}”>
                                            ^                        ^

使用普通的

<link rel="stylesheet" type="text/css" href="{% static 'index.css' %}">