我收到了一个404,因为我的静态文件,页面加载,但当检查控制台时,它传递以下错误,我已经在这个问题上绞尽脑汁了。如果有人能为我指出正确的方向,我将不胜感激!:
127.0.0.1/:10 GET http://127.0.0.1:8000/static/css/all.css net::ERR_ABORTED 404 (Not Found)
127.0.0.1/:12 GET http://127.0.0.1:8000/static/css/bootstrap.css net::ERR_ABORTED 404 (Not Found)
127.0.0.1/:14 GET http://127.0.0.1:8000/static/css/style.css net::ERR_ABORTED 404 (Not Found)
127.0.0.1/:16 GET http://127.0.0.1:8000/static/css/lightbox.min.css net::ERR_ABORTED 404 (Not Found)
127.0.0.1/:26 GET http://127.0.0.1:8000/static/js/jquery-3.3.1.min.js net::ERR_ABORTED 404 (Not Found)
127.0.0.1/:28 GET http://127.0.0.1:8000/static/js/lightbox.min.js net::ERR_ABORTED 404 (Not Found)
127.0.0.1/:27 GET http://127.0.0.1:8000/static/js/bootstrap.bundle.min.js net::ERR_ABORTED 404 (Not Found)
127.0.0.1/:29 GET http://127.0.0.1:8000/static/js/main.js net::ERR_ABORTED 404 (Not Found)
127.0.0.1/:28 GET http://127.0.0.1:8000/static/js/lightbox.min.js net::ERR_ABORTED 404 (Not Found)
127.0.0.1/:29 GET http://127.0.0.1:8000/static/js/main.js net::ERR_ABORTED 404 (Not Found)
下面是settings.py文件中的一些代码:
DEBUG = True
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',
],
},
},
]
STATIC_ROOT= os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
STATICFILES_DIR =[
os.path.join(BASE_DIR, '/btre/static/')
]
下面是base.html文件:
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Font Awesome -->
<link rel="stylesheet" href="{% static 'css/all.css' %}">
<!-- Bootstrap -->
<link rel="stylesheet" href="{% static 'css/bootstrap.css' %}">
<!-- Custom -->
<link rel="stylesheet" href="{% static 'css/style.css' %}">
<!-- Lightbox -->
<link rel="stylesheet" href="{% static 'css/lightbox.min.css' %}">
<title>BT Real Estate</title>
</head>
<body>
{% block content %} {% endblock %}
<script src="{% static 'js/jquery-3.3.1.min.js' %}"></script>
<script src="{% static 'js/bootstrap.bundle.min.js' %}"></script>
<script src="{% static 'js/lightbox.min.js' %}"></script>
<script src="{% static 'js/main.js' %}"></script>
</body>
</html>
This is my directory/file path to the static folder containing the CCS, JS, IMAGES etc
以下是我运行collect static时的临时输出:
(venv) computer_name:btre_project user.name$ python manage.py collectstatic
132 static files copied to '/Users/user.name/dev/btre_project/static'.
Here's an image of the collected static folders after being copied
发布于 2020-12-20 16:31:14
这是STATICFILES_DIRS
而不是STATICFILES_DIR
最后做一个python manage.py collectstatic
https://stackoverflow.com/questions/65381522
复制相似问题