【发布时间】:2019-10-03 06:23:18
【问题描述】:
我一直试图在我的 Django 项目中提供我的静态文件,但是它找不到或加载它。我尝试了不同的方法,但似乎都无法解决问题。
静态文件夹与 manage.py 位于同一目录中。
另外,我已经安装了WitheNoise,但也没有解决问题。
另外:我正在使用docker,我已经完成了收集静态并检查了容器。所有文件都正确存在。
Django 版本 = 2.0.1
开发环境
代码结构:
项目
- assets
- config
- docs
- project-root
- - static
- - manage.py
- - templates
- - apps
- - project-root
- - - settings.py
- - - urls.py
...
...
setting.py
INSTALLED_APPS = [
'pages.apps.PagesConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
STATIC_URL = '/static/'
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
html文件
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<!-- Bootstrap -->
<link rel="stylesheet" href="{% static "css/bootstrap.css" %}">
<link rel="stylesheet" href="{% static "css/jquery.bxslider.css" %}">
<!-- Custom -->
<link rel="stylesheet" href="{% static "css/style.css" %}">
<link rel="stylesheet" href="{% static "css/animate.css" %}">
</head>
如果我需要在帖子中添加对您有所帮助的其他内容,请告诉我。 谢谢,
【问题讨论】: