【发布时间】:2023-02-25 03:47:31
【问题描述】:
我想将一个 css 文件连接到这个 html 文件,我想通过 {%load struct%} 添加它
`{% load static %}
<!DOCTYPE html>
<html lang="ru">
<head>
<title>Brewtopia Cafe form</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="{% static 'css/style_contact.css' %}">
</head>
<body>
<header>`
这是应用程序中的 urls.py
`from django.urls import path
from . import views
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('', views.Brewtopia_view, name='brewtopia'),
path('Contact/', views.Contact_view, name='contact')
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
`
这些是应用程序中的 views.py
`from django.shortcuts import render
def Brewtopia_view(request):
return render(request, 'Brewtopia.html')
def Contact_view(request):
return render(request, 'Contact.html')
`
settings.py 静态设置
`STATIC_URL = '/static/'
STATICFILES_DIRS = [
BASE_DIR / "static",
]`
css 文件位于文件夹 C:\Projects\brew\brewtopia\users\static\users\css
我添加了struct,想上传一个css文件,但是错误在截图中 enter image description here 但即使你删除 {%loadstruct%} 它也不会工作
【问题讨论】: