如何使静态样式表在Django中工作? [英] How to make static style-sheet working in django?

查看:59
本文介绍了如何使静态样式表在Django中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过在普通的 html 中运行此代码,它也可以使用样式运行。但是,每当我在Django中运行它时,它都不会运行,只会显示文本。

By running this code in normal html it runs with style also. But whenever I run it in django it does not run and just show me text.

views.py

def index(request):
    return render(request, 'index.html');

主网址

urlpatterns = [
    path('', include('app1.urls')),
    path('admin/', admin.site.urls)
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

index.html

<!-- Animate.css -->
<link rel="stylesheet" href="{% static '../static/css/animate.css' %}">
<!-- Icomoon Icon Fonts-->
<link rel="stylesheet" href="{% static '../static/css/icomoon.css' %}">
<!-- Simple Line Icons -->
<link rel="stylesheet" href="{% static '../static/css/simple-line-icons.css' %}">

<section id="fh5co-home" data-section="home" style="background-image: url(../static/images/W1.png);" data-stellar-background-ratio="0.5">
    <div class="gradient"></div>
    <div class="container">
        <div class="text-wrap">
            <div class="text-inner">
                <div class="row">
                    <div class="col-md-8 col-md-offset-2 text-center">
                     <h1 class="to-animate">Welcome in the World of White Hats</h1>
                        <h2 class="to-animate">Your Problem with auto Solution</h2>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

文件夹结构

推荐答案

而不是:

href = {%static'../ static /...

尝试:

href = {%static'../css/...

此外,还需要包括以下内容: {%load static%} 您要使用的所有模板的开头静态文件。

Also, need to include this: {% load static %} at the beginning of all your templates where you want to use static files.

这篇关于如何使静态样式表在Django中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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