Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django静态文件未加载且没有错误标志_Python_Html_Css_Django_Django Templates - Fatal编程技术网

Python Django静态文件未加载且没有错误标志

Python Django静态文件未加载且没有错误标志,python,html,css,django,django-templates,Python,Html,Css,Django,Django Templates,当我运行django服务器并尝试加载HTML文件时,它并没有加载CSS文件。我没有看到终端或网站本身有任何错误——只是在后台加载动画。在settings.py中设置静态文件后,我在终端上运行collectstatic,它在主文件区域生成了一个新的静态文件,其中包含所有CSS/JS/fonts文件 ~filepath ├── static/ │ ├── static/ │ │ └── admin/ │ │ └── css/ │ └── fonts/ │

当我运行django服务器并尝试加载HTML文件时,它并没有加载CSS文件。我没有看到终端或网站本身有任何错误——只是在后台加载动画。在settings.py中设置静态文件后,我在终端上运行collectstatic,它在主文件区域生成了一个新的静态文件,其中包含所有CSS/JS/fonts文件

~filepath

├── static/
│   ├── static/
│   │   └── admin/
│   │   └── css/    
│       └── fonts/
│       └── images/
│       └── js/
├── templates/
│   └── base.html/
│   └── _partials/
│      └── footer.html
│      └── navbar.html
│   └── pages/   
│      └── index.html
│      └── about.html
~settings.py

STATIC_ROOT = os.path.join(BASE_DIR,'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'tvfb/static')
]
~base.html
{%load static%}
文件
{%include'\u partials/\u navbar.html%}
{%block content%}
{%endblock%}
{%include'\u partials/\u footer.html%}

清除静态文件目录:

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'tvfb/static')
]
将保持如下状态:

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

运行
python manage.py collectstatic
,不要忘了删除浏览器的缓存

,说服务器你是指在apache2或ngix上?它工作了!非常感谢你!我可以要求更多关于删除静态文件和浏览器缓存的说明吗?我想更深入地了解。再次感谢!很高兴它成功了!您可以参考本文了解何时使用StaticFileDir的更多信息。此外,最好清理缓存,因为浏览器总是试图从缓存中提供页面,因此有时会出现更新未显示的情况。@YeongHeo不要忘记接受答案,以便其他人也能轻松找到。感谢您的澄清!很抱歉,我刚刚接受了你的回答-我第一次使用Stackoverflow,但再次感谢!
~views.py
def index(request):
    return render(request, 'pages/index.html')

def about(request):
    return render(request, 'pages/about.html')
~base.html
{% load static %}

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link href="https://fonts.googleapis.com/css?family=Poppins:200,300,400,500,600,700,900" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Playfair+Display:400,400i,700,700i,900,900i" rel="stylesheet">

    <link rel="stylesheet" href="{% static 'css/open-iconic-bootstrap.min.css' %}">
    <link rel="stylesheet" href="{% static 'css/animate.css' %}">

    <link rel="stylesheet" href="{% static 'css/owl.carousel.min.css' %}">
    <link rel="stylesheet" href="{% static 'css/owl.theme.default.min.css' %}">
    <link rel="stylesheet" href="{% static 'css/magnific-popup.css' %}">

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

    <link rel="stylesheet" href="{% static 'css/ionicons.min.css' %}">

    <link rel="stylesheet" href="{% static 'css/flaticon.css' %}">
    <link rel="stylesheet" href="{% static 'css/icomoon.css' %}">
    <link rel="stylesheet" href="{% static 'css/style.css' %}">

</head>
<body>
    <!-- Nav Bar -->
    {% include '_partials/_navbar.html'%}
    <!-- Main Content -->
    {% block content %}
    {% endblock %}
    <!-- footer -->
    {% include '_partials/_footer.html'%}


    <!-- loader -->
    <div id="ftco-loader" class="show fullscreen"><svg class="circular" width="48px" height="48px"><circle class="path-bg" cx="24" cy="24" r="22" fill="none" stroke-width="4" stroke="#eeeeee"/><circle class="path" cx="24" cy="24" r="22" fill="none" stroke-width="4" stroke-miterlimit="10" stroke="#F96D00"/></svg></div>


    <script src="{% static 'js/jquery.min.js' %}"></script>
    <script src="{% static 'js/jquery-migrate-3.0.1.min.js' %}"></script>
    <script src="{% static 'js/popper.min.js' %}"></script>
    <script src="{% static 'js/bootstrap.min.js' %}"></script>
    <script src="{% static 'js/jquery.easing.1.3.js' %}"></script>
    <script src="{% static 'js/jquery.waypoints.min.js' %}"></script>
    <script src="{% static 'js/jquery.stellar.min.js' %}"></script>
    <script src="{% static 'js/owl.carousel.min.js' %}"></script>
    <script src="{% static 'js/jquery.magnific-popup.min.js' %}"></script>
    <script src="{% static 'js/aos.js' %}"></script>
    <script src="{% static 'js/jquery.animateNumber.min.js' %}"></script>
    <script src="{% static 'js/scrollax.min.js' %}"></script>
    <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBVWaKrjvy3MaE7SQ74_uJiULgl1JY0H2s&sensor=false"></script>
    <script src="{% static 'js/google-map.js' %}"></script>
    <script src="{% static 'js/main.js' %}"></script>

</body>
</html>
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'tvfb/static')
]
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR,'static')