【发布时间】:2020-06-20 14:18:43
【问题描述】:
我写了这个,我的静态文件没有加载
我的设置.py
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
我的 urls.py
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
错误
[08/Mar/2020 16:51:18] "GET /static/bootstrap/bootstrap.min.css HTTP/1.1" 404 1808
我的目录
├───.idea
│ ├───codeStyles
│ ├───dataSources
│ │ └───d4ce3b9a-7046-4b9c-88b6-dab8cf342341
│ │ └───storage_v2
│ │ └───_src_
│ │ └───database
│ │ └───iotkaran.u-MyVw
│ │ └───schema
│ └───inspectionProfiles
├───accounts
│ ├───migrations
│ │ └───__pycache__
│ ├───templates
│ │ └───accounts
│ └───__pycache__
├───iotkaran
│ └───__pycache__
├───static
│ ├───admin
│ │ ├───css
│ │ │ └───vendor
│ │ │ └───select2
│ │ ├───fonts
│ │ ├───img
│ │ │ └───gis
│ │ └───js
│ │ ├───admin
│ │ └───vendor
│ │ ├───jquery
│ │ ├───select2
│ │ │ └───i18n
│ │ └───xregexp
│ ├───bootstrap
│ ├───bootstrap-4.4.1-dist
│ │ ├───css
│ │ └───js
│ └───img
├───templates
└───venv
├───Include
├───Lib
│ └───site-packages
└───Scripts
和我的 HTML
<!DOCTYPE html>
<html lang="fa-IR">
{% load static %}
<head>
<meta charset="UTF-8">
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" href="{% static 'bootstrap/bootstrap.min.css' %}">
<link rel="shortcut icon" type="image/png" href="{% static 'img/favicon.png' %}">
</head>
我将文件夹位置从 user/[user] 更改为 myDocument\myprojects。我也将所有人添加为文件夹的所有者。但仍然无法正常工作。 提前谢谢你
【问题讨论】:
-
您是否使用过 {%load staticfiles%},请您设置更多关于您将使用的 html 文件的详细信息?
-
请显示您的文件夹结构并说明 DEBUG=true 还是 false。
-
@IvanStarostin 是的,调试是真的
-
@abdelhamedabdin 我使用 {% load static %}
-
@IvanStarostin 我现在无法访问我的电脑,但我会尽快发送
标签: django python-3.x bootstrap-4 django-templates