Html 未找到Django 1.10.2 manage.py runserver:///静态/索引.css“;

Html 未找到Django 1.10.2 manage.py runserver:///静态/索引.css“;,html,django,templates,Html,Django,Templates,我可能犯了一个简单的错误,但经过几天的故障排除和迭代,我无法找到问题的根源。尽管我尽了最大努力,Django拒绝加载我的静态css文件,但确实加载了html,每次都会抛出完全相同的错误。未找到错误:/“/static/index.css”这是我当前的代码: APP\u NAME/APP\u NAME/templates/index.html {% load staticfiles %} <link rel="stylesheet" type="text/css" href=

我可能犯了一个简单的错误,但经过几天的故障排除和迭代,我无法找到问题的根源。尽管我尽了最大努力,Django拒绝加载我的静态css文件,但确实加载了html,每次都会抛出完全相同的错误。未找到错误:/“/static/index.css”这是我当前的代码:

APP\u NAME/APP\u NAME/templates/index.html

    {% load staticfiles %}
    <link rel="stylesheet" type="text/css" href=“{% static 'index.css' %}”>
APP\u NAME/APP\u NAME/url.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)
    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)
    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


    # SECURITY WARNING: don't run with debug turned on in production!

    DEBUG = True

    ALLOWED_HOSTS = []


    # Application definition

    INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
    ]



    ROOT_URLCONF = 'APP_NAME.urls'

    STATIC_URL = "/static/"
    STATIC_ROOT = os.path.join(BASE_DIR, "APP_NAME/static/")

    STATICFILES_DIR = [
            os.path.join(BASE_DIR, "APP_NAME/static/")
    ]
APP\u NAME/APP\u NAME/settings.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)
    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)
    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


    # SECURITY WARNING: don't run with debug turned on in production!

    DEBUG = True

    ALLOWED_HOSTS = []


    # Application definition

    INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
    ]



    ROOT_URLCONF = 'APP_NAME.urls'

    STATIC_URL = "/static/"
    STATIC_ROOT = os.path.join(BASE_DIR, "APP_NAME/static/")

    STATICFILES_DIR = [
            os.path.join(BASE_DIR, "APP_NAME/static/")
    ]

您不需要添加静态URL—如果DEBUG=True,django将为您搜索并提供静态文件。试一试

findstatic index --verbosity=2

查看实际搜索静态文件的位置。正如这里所建议的,如果DEBUG=True,则无需添加静态URL-django搜索并为您提供静态文件。试一试

findstatic index --verbosity=2

查看实际搜索静态文件的位置。正如这里所建议的,您的报价类型错误

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

^                        ^
使用普通的

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

您的引号类型错误

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

^                        ^
使用普通的

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


这是我的Macbook Pro键盘上的默认引号。当我复制和粘贴时,编码可能发生了变化。@torchhound尝试删除它们并重新键入。我想你看不到任何不同,因为你的字体。我复制并粘贴了你的修复,它工作了。我很惊讶,但非常感谢你!这是Macbook Pro键盘上的默认引号。当我复制和粘贴时,编码可能发生了变化。@torchhound尝试删除它们并重新键入。我想你看不到任何不同,因为你的字体。我复制并粘贴了你的修复,它工作了。我很惊讶,但非常感谢你!这非常有用,
findstatic
显示了唯一的搜索位置为
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site packages/django/contrib/admin/static
。Django未在my APP_NAME/APP_NAME/static文件夹中搜索。如何在那里进行Django搜索?默认情况下,它会在STATICFILES\u DIRS中定义的所有位置以及由INSTALLED\u apps设置指定的应用程序的“static”目录中查找。这可以通过STATICFILES\u Finder和STATICFILES\u DIRS设置进行配置-因此,您可以将APP\u NAME/APP\u NAME/static设置为STATICFILES\u DIRS。或者,将静态文件放到某个应用程序的static/dir中可能会更容易。我意识到我使用了
STATICFILES\u dir
而不是
STATICFILES\u DIRS
,但即使我纠正了这个错误并添加了
STATICFILES\u FINDERS
manage.py runserver仍然返回
未找到:/“/static/index.css”
另外,我修复了输入错误
findstatic
现在找到
index.css
,但是
manage.py runserver
仍然返回
Not Found
,这非常有帮助,
findstatic
将唯一的搜索位置显示为
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site packages/django/contrib/admin/static
。Django未在my APP_NAME/APP_NAME/static文件夹中搜索。如何在那里进行Django搜索?默认情况下,它会在STATICFILES\u DIRS中定义的所有位置以及由INSTALLED\u apps设置指定的应用程序的“static”目录中查找。这可以通过STATICFILES\u Finder和STATICFILES\u DIRS设置进行配置-因此,您可以将APP\u NAME/APP\u NAME/static设置为STATICFILES\u DIRS。或者,将静态文件放到某个应用程序的static/dir中可能会更容易。我意识到我使用了
STATICFILES\u dir
而不是
STATICFILES\u DIRS
,但即使我纠正了这个错误并添加了
STATICFILES\u FINDERS
manage.py runserver仍然返回
未找到:/“/static/index.css”
另外,我修复了输入错误
findstatic
现在找到
index.css
,但是
manage.py runserver
仍然返回
未找到