所以问题在于Django无法识别静态文件。无论我尝试了什么,它都不起作用。我尝试将全局搜索方式更改为CSS文件的直接URL,但这些都没有起作用。
我的项目结构如下: 这是我的代码:
我的项目结构如下: 这是我的代码:
DEBUG = True
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
STATIC_URL = '/static/'
STATIC_DIRS = [os.path.join(BASE_DIR, "static")]
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static_cdn")
from django.contrib import admin
from django.urls import path
from something.views import *
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', home),
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL,document_root=settings.STATIC_ROOT)
{% load static from staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Monkeys</title>
<link rel="stylesheet" type="text/css" href="{% static 'css/file.css' %}"/>
</head>
我在互联网上找不到答案,希望你能帮忙。
python manage.py collectstatic
吗?此外,问题是在调试模式还是生产模式下发生的(或两种模式都有问题)? - Johan/Users/ivanizumov/Desktop/environment/static_cdn/css/file.css
? - Ivan Starostin