【问题标题】:How to link template of html to start working in django? [duplicate]如何链接html模板以开始在django中工作? [复制]
【发布时间】:2020-02-02 06:39:40
【问题描述】:

通过在普通 HTML 中运行此代码,它也可以以样式运行。但是每当我在 django 中运行它时,它就会运行并只显示一个文本。我申请了../static/css/animate.css../css/animate.csscss/animate.css,但它们都没有工作。我通过提供 STATIC_ROOT 对 settings.py 进行了更改,但仍然只显示文本。

settings.py

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

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

{% load static %}

<!-- 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>

文件夹结构

【问题讨论】:

  • STATIC_URL 和 STATiC_ROOT 的设置是什么?
  • STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
  • 我不是通过 StackOverflow 找到答案的,但感谢您的支持

标签: html css django python-3.x


【解决方案1】:

尝试从 index.html 中删除“../static/”
另外不要忘记在重新启动服务器之前运行:“python manage.py collectstatic”

【讨论】:

    猜你喜欢
    • 2015-10-17
    • 2019-06-04
    • 1970-01-01
    • 2013-11-14
    • 2023-04-04
    • 2012-11-22
    • 2013-05-26
    • 2017-03-17
    • 2019-08-11
    相关资源
    最近更新 更多