gpt4 book ai didi

django - TemplateSyntaxError at/allVms/无效 block 标记 : 'static'

转载 作者:行者123 更新时间:2023-12-01 06:15:11 25 4
gpt4 key购买 nike

我想在 Django 中做如何使用静态 block 等 block 集成 css 和图像文件的方式,我编写了 html 代码及其 css 文件但是当我想显示它时无法显示它出现在我一个错误。下面是我的代码

base.html:

<!DOCTYPE html>
<html lang="en">
<head>
<title> {% block title %} My Base Template {% endblock %} </title>
<link rel="stylesheet" type="text/css" href="{% static "assets/css/base.css"%}">
</head>
<body>
<div id="page">
<div id="sidebar">
{% block sidebar %}
<ul>
<li><a href="/allVms">List all Servers </a></li>
<li><a href="/FormCreateVm">Create New VM</a></li>
{% endblock %}
</body>
</htlm>

base.css:

body{ text-align:center;}
#page{
width:968px;
text-align:left;
margin:10px auto 20px auto;
background-color:grey;
}
#sidebar{
float:left;
width:280px;
border:1px solid red;
}
#content{
float:left;
width:608px;
border:1px solid red;
padding:18px;
}

设置.py:

...
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_URL = '/static/'

STATICFILES_DIRS = (
('assets','/home/rochdi/Desktop/PyStack/static'),
)
...

Assets 是对从主页到包含 css 和图像文件夹的静态文件夹的路径的引用

错误是: enter image description here

最佳答案

使用static标签前,需要加载staticfiles模板标签库。尝试将此添加到模板文件的顶部:

{% load staticfiles %}

关于django - TemplateSyntaxError at/allVms/无效 block 标记 : 'static' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29978958/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com