简体   繁体   English

静态文件不是注册标签,静态文件未加载

[英]Staticfiles not a registered tag and staticfiles not loading

My staticfiles will not load no matter what and I'm at the point where I've looked through stackoverflow and read documentation for five hours so I need help.我的静态文件无论如何都不会加载,而且我已经浏览了 stackoverflow 并阅读了五个小时的文档,所以我需要帮助。

Here's my URL for urls.py这是我的 urls.py 网址

urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'', include('notebook.urls'))
]
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

urlpatterns += staticfiles_urlpatterns()

Meanwhile this is my settings for my project and I'm egregiously been trying to figure out why my staticfiles have not loaded.同时,这是我为我的项目设置的设置,我一直在试图弄清楚为什么我的静态文件没有加载。 I'm not running this in a virtualenv so those related issues have been addressed I've looked over the Django documentation to try and find where in my setting the reason the staticfiles are not loading and I after hours of that and staackoverflow not a single answer has availed.我没有在 virtualenv 中运行它,所以那些相关的问题已经得到解决我已经查看了 Django 文档,试图找到在我的设置中静态文件没有加载的原因,经过几个小时的处理,staackoverflow 不是一个答案已用。

This is my settings file for the project这是我的项目设置文件

    """
Django settings for onesky project.

Generated by 'django-admin startproject' using Django 1.10.5.

For more information on this file, see
https://docs.djangoproject.com/en/1.10/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.10/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/

# Static file directory
TEMPLATE_DIR = os.path.join(BASE_DIR, "templates")
# Static files for multiple directories
STATICFILES_DIR = os.path.join(BASE_DIR, "static")
# Media file directory
MEDIA_DIR = os.path.join(BASE_DIR, "media")

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'q*6q$)mqhr**pwaj4m!8km&2i7s2ewu+lg%7p$*pm6+8!l8cwf'

# 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.staticfiles',
    'django.contrib.sessions',
    'django.contrib.messages',
    'rest_framework',
    'notebook',

]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'onesky.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [TEMPLATE_DIR],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'django.template.context_processors.media',
            ],
        },
    },
]

WSGI_APPLICATION = 'onesky.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/1.10/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = STATICFILES_DIR

# Media Root
MEDIA_ROOT = MEDIA_DIR
MEDIA_URL = '/media/'

Just for completeness here is also wgsi.py file为了完整起见,这里也是 wgsi.py 文件

"""
WSGI config for onesky project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "onesky.settings")

application = get_wsgi_application()

Here's my template code这是我的模板代码

<!DOCTYPE html>
<html lang="en">
<head>
{% load staticfiles %}

    <meta charset="UTF-8">
    <title>OneSky</title>
    <link rel="stylesheet" href="{% load static "css/normalize.css" %}">
    <link rel="stylesheet" href="{% load static'css/home.css' %}">
    <link rel="stylesheet" href="{% load static '/css/notebook.css' %}">
    <link rel="stylesheet" href="{% load static 'css/skeleton.css' %}">
</head>
<body>
<div class="row" style="padding-top: 1%;">
    <div class="nav">
        <div class="three columns">
            <div class="logo">OneSky</div>
        </div>
        <!--
           @TODO:Change to class based styling
        -->
        <div class="seven columns" style="height: 100%">
            <div class="spacer"></div>
        </div>
        <div class="one column">
            <img src="{% load static 'img/settings-cog.png' %}" class="icon">
        </div>
        <div class="one column">
            <img src="img/account.png" class="icon">
        </div>
    </div>
</div>
<div class="data-container">
<div class="row">

        <div class="three columns" style="overflow: hidden">
            <div class="scroll-container">
            <div class="note-container">
            <div class="row">
                <div class="eight columns">
                    <h2 class="note header"> Notebook </h2>
                </div>
                <div class="two columns">
                    <img src="img/add-button.png" class="icon">

                </div>
                <div class="two columns">
                    <img src="img/list-button.png" class="icon">
                </div>
            </div>
                <div id="content" class="hiddenscrollbars">
                <hr>
                    {% for post in posts %}

                            <div class="row">
                    <div class="note-title">
                        <h4> {{ post.title }}</h4>
                    </div>
                </div>
                    {% endfor %}

            </div>

                </div>

        </div>
            </div>
    </div>


<div class="eight columns">
    <div class="row">
        <h3 class="selected-note-title">Select Something</h3> <span><button class="submit" title="submit">Save</button></span>
    </div>
    <div class="scrolling-container">
        <div class="editor-container">
        </div>

    </div>
</div>

</div>
</div>








</body>
<!-- Include the Quill library -->
<script src="js/quill.js"></script>
<!-- Initialize Quill editor -->
<script src="js/notebook.js"></script>


</html>

Thank you in advance for assistance预先感谢您的帮助

You need to use static to get the url of static files, instead you're using load static , which confuses Django to think you're loading a custom tag.您需要使用static来获取静态文件的 url,而不是使用load static ,这让 Django 误以为您正在加载自定义标签。

The only instance where you need to use load is:您需要使用load的唯一实例是:

{% load staticfiles %}

Change these:改变这些:

<link rel="stylesheet" href="{% load static "css/normalize.css" %}">
<link rel="stylesheet" href="{% load static'css/home.css' %}">
<link rel="stylesheet" href="{% load static '/css/notebook.css' %}">
<link rel="stylesheet" href="{% load static 'css/skeleton.css' %}">
....
....
<img src="{% load static 'img/settings-cog.png' %}" class="icon">

To:到:

<link rel="stylesheet" href="{% static "css/normalize.css" %}">
<link rel="stylesheet" href="{% static'css/home.css' %}">
<link rel="stylesheet" href="{% static '/css/notebook.css' %}">
<link rel="stylesheet" href="{% static 'css/skeleton.css' %}">
....
....
<img src="{% static 'img/settings-cog.png' %}" class="icon">

At the starting of your hrml templates, you might have to use在您的 hrml 模板开始时,您可能必须使用

{& load static %} not staticfiles {& 加载静态 %} 不是静态文件

That's why templatesytaxerror is raised.这就是 templatesytaxerror 被提出的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Django TemplateSyntaxError - 'staticfiles' 不是注册的标签库 - Django TemplateSyntaxError - 'staticfiles' is not a registered tag library &#39;staticfiles&#39; 不是注册标签库:这些解决方案不起作用 - 'staticfiles' is not a registered tag library: These solutions don't work Django 静态文件未加载 - Django staticfiles not loading Django / Python静态文件未加载 - Django/Python staticfiles is not loading Pythonanywhere'staticfiles'不是有效的标记库:找不到模板库staticfiles - Pythonanywhere 'staticfiles' is not a valid tag library: Template library staticfiles not found django_rest_swagger - &#39;staticfiles&#39; 不是注册的标签库。 必须是以下之一: - django_rest_swagger - 'staticfiles' is not a registered tag library. Must be one of: /en/admin/login/ 'staticfiles' 处的 TemplateSyntaxError 不是已注册的标签库。 必须是以下之一: - TemplateSyntaxError at /en/admin/login/ 'staticfiles' is not a registered tag library. Must be one of: Django 部署 ElasticBeanstalk StaticFiles (JS/CSS) 未加载 - Django Deploy ElasticBeanstalk StaticFiles(JS/CSS) not loading Django静态文件未在生产中加载 - Django staticfiles aren't loading in production 配置不当的静态文件 - ImproperlyConfigured staticfiles
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM