提问人:Mangi 提问时间:9/28/2023 最后编辑:Mangi 更新时间:9/28/2023 访问量:45
在 django 项目中使用 HTML 模板
Using HTML Template with django project
问:
我遇到的问题是我无法将图片和CSS从模板加载到django。 以下是文件的结构。
[![在此输入图片描述][3]][3] [![在此输入图片描述][4]][4] [![在此输入图片描述][5]][5]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Electro - HTML Ecommerce Template</title>
<!-- Load static files -->
<!-- Google font -->
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,500,700" rel="stylesheet">
<!-- Bootstrap -->
<link type="text/css" rel="stylesheet" href="{% static 'assets/css/bootstrap.min.css' %}"/>
<!-- Slick -->
<link type="text/css" rel="stylesheet" href="{% static 'assets/css/slick.css' %}"/>
<link type="text/css" rel="stylesheet" href="{% static 'assets/css/slick-theme.css' %}"/>
<!-- nouislider -->
<link type="text/css" rel="stylesheet" href="{% static 'assets/css/nouislider.min.css' %}"/>
<!-- Font Awesome Icon -->
<link rel="stylesheet" href="{% static 'assets/css/font-awesome.min.css' %}">
<!-- Custom stlylesheet -->
<link type="text/css" rel="stylesheet" href="{% static 'assets/css/style.css' %}"/>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="{% static 'https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js' %}"></script>
<script src="{% static 'https://oss.maxcdn.com/respond/1.4.2/respond.min.js' %}"></script>
<![endif]-->
</head>
答:
0赞
Mamatkasym Mamarasul
9/28/2023
#1
您必须在 html 文件中定义变量并将其加载到文件中。STATIC_URL
settings
有关详细信息,请点击此文档链接 https://docs.djangoproject.com/en/4.2/howto/static-files/。
评论
0赞
Mangi
9/28/2023
STATIC_URL = 'static/' STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')] 我把它放在 settings.py 它仍然不起作用
0赞
Mahammadhusain kadiwala
9/28/2023
#2
在 settings.py 中设置静态路径
STATIC_URL = '/main/main/static/'
评论
{}