【问题标题】:Visibility problem for static files -- django静态文件的可见性问题——django
【发布时间】:2020-08-16 10:40:32
【问题描述】:

我在 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>

网址 - 项目:

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 替换为 STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')] 到您的 settings.py 中

标签: python python-3.x django django-views


【解决方案1】:

试试这个:

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

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

【讨论】:

    猜你喜欢
    • 2014-09-11
    • 2011-06-11
    • 1970-01-01
    • 2020-11-06
    • 2018-10-21
    • 2013-11-22
    • 2018-07-26
    • 2016-11-13
    • 2018-09-10
    相关资源
    最近更新 更多