【问题标题】:python built in server not loading css filepython内置服务器不加载css文件
【发布时间】:2020-04-27 12:24:26
【问题描述】:

为什么它在 Django 中不起作用?像这样的浏览器有错误。

its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled. 

在文件 html 中有:

<link rel="stylesheet" href="{% static 'nowy.css' %}">

在 settings.py 中看起来像:

STATIC_URL = '/static/'

目录是:app > static > nowy.css

我找不到错误在哪里。

【问题讨论】:

    标签: python django frameworks


    【解决方案1】:

    这可能是由您的设置静态变量或您对 css 文件的寻址引起的。 首先尝试检查设置。 你是否包含了 STATICFILES_DIRS ?

    STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
    ]
    

    并尝试检查模板设置。 你包括加载器吗?

    TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')]
        ,
        'APP_DIRS': False,
        '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',
            ],
            'loaders': [
                'django.template.loaders.filesystem.Loader',
                'django.template.loaders.app_directories.Loader',
            ],
        },
    },
    ]
    

    现在尝试检查您的 css 文件的路径。

    • 项目
    • app_name
      • 静态
        • app_name
          • style.css

    在你的 html 中是这样的

    {% load static %}
    <link rel="stylesheet" href="{% static "app_name/style.css" %}">
    

    【讨论】:

      猜你喜欢
      • 2014-05-15
      • 1970-01-01
      • 2015-10-05
      • 1970-01-01
      • 2016-11-11
      • 1970-01-01
      • 1970-01-01
      • 2015-12-02
      相关资源
      最近更新 更多