CSS文件未加载 [英] CSS file is not loaded

查看:113
本文介绍了CSS文件未加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Django应用程序,无法弄清楚为什么未加载CSS文件。

I have a simple Django app and I cannot figure out why my CSS file is not loaded. Any help to nail the problem is appreciated!

我得到的错误是:

GET http://127.0.0.1:8000/static/aztracker/css/mystyle.css net :: ERR_ABORTED

这是我的CSS文件所在的位置:
myproject / aztracker / static / aztracker / css / mystyle.css

This is where my css file is sitting: myproject/aztracker/static/aztracker/css/mystyle.css

code_search_form.html:

{% load staticfiles %}
{% load static %}
<!DOCTYPE html>
<head>
    <meta charset="utf-8" />
    <title>Search Code</title>
    <!-- CUSTOM STYLES -->
    <link rel="stylesheet" type="text/css" href="{% static 'aztracker/css/mystyle.css' %}">
</head>
<body>
    <form method="POST" action="/search/">
        {% csrf_token %}
        <input  type="text" maxlength="2"  style="text-transform:uppercase"  placeholder="Search Country Code.." name="cc_textfield" id="cc_input">
        <button type="submit" id="search_btn">Search</button>
    </form>
</body>

mystyle.css:

#search_btn {
    color:red;
}

setting.py:

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

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
    '/aztracker/static/',
]


推荐答案

我自己弄清楚了:

问题是 setting.py 文件,其中定义了静态文件夹。我注释了 STATIC_ROOT 并成功了。我猜他们不能共存。

the problems was the setting.py file where static folder is defined. I commented out STATIC_ROOT and it worked. I guess they cannot co-exist.

这篇关于CSS文件未加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆