服务器正在运行时在控制台中的输出:
Not Found: /css/bootstrap.css
我很确定我弄错了路径,但是根据我的项目结构,我不知道正确的路径是什么(如下)。
settings.py:
STATIC_URL = '/static/'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
项目树:
Grand Folder
app1
settings.py
static
app1
css
bootstrap.css
app2
app3
templates
base.html
base.html:
{% load i18n %}
{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="{{ STATIC_URL }}/css/bootstrap.css" />
<title>{% block title %}User test{% endblock %}</title>
</head>
最佳答案
您应该在base.html中使用static
模板标记:
编辑
{% load static %}
<link rel="stylesheet" href="{% static "app1/css/bootstrap.css" %}" />