我已经尝试了我所知道的一切来解决这个问题,除了 css 之外,所有静态文件都可以正常工作
视图.py
from django.http.response import HttpResponse
from django.shortcuts import render
def index(response):
return render(response , "main/index.html")
html头
{% extends 'main/base.html' %}
{% load static %}
<!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.0">
<link rel="stylesheet" href= "{%static "main/css/index.css" %}">
<title> Home Page </title>
</head>
请注意,如果这会影响任何东西,我会在基本文件中使用引导程序
设置.py
STATIC_URL = '/static/'
STATIC_ROOT = "/Users/aryankaushik/Desktop/visual studio code /django/assets"
STATICFILES_DIRS = [
BASE_DIR / "static",
]
项目目录
├── admin.py
├── apps.py
├── migrations
│ ├── __init__.py
│ └── __pycache__
│ └── __init__.cpython-39.pyc
├── models.py
├── static
│ └── main
│ ├── css
│ │ ├── base.css
│ │ └── index.css
│ ├── img
│ │ ├── electronics.jpeg
│ │ ├── furniture.jpeg
│ │ └── nature.jpeg
│ └── js
│ └── index.js
├── templates
│ └── main
│ ├── base.html
│ ├── contact.html
│ └── index.html
├── tests.py
├── urls.py
└── views.py
我确信文件夹路径正确,因为图像渲染正确..
先感谢您