静态文件的可见性问题--django



我在django中连接了静态文件,但它们不会连接,你能帮忙吗?

设置:

STATICFILES_DIRS = [
"web_page/static",
]
STATIC_URL = '/static/'
STATIC_ROOT = '/static/'

index.html:

<!DOCTYPE html>
{% load static %}
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="{% static "css/standart_template.css" %}" rel="stylesheet" type="text/css" >
<title>HouseVOP</title>
</head>

url-项目:

from django.contrib import admin
from django.urls    import path, include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/',      admin.site.urls),
path('',            include('web_page.urls')),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

网址-应用程序:

from django.urls import path
from .views      import FormListView, Success
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('',            FormListView,     name = 'home'),
path('success/',    Success,          name = 'success')
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

在转到这里之前,我搜索了很多网站,所以现在我可能根本看不到什么。在代码的第一个版本中,我将静态文件的路径与os.path.join(BASE_DIR等(一起放置,但它不起作用…

试试这个:

STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]

不要使用web_page/static。不需要。

最新更新