问题描述
请帮助我在此docker django配置中提供静态文件。
我的创建的p>
我以前使用过此设置,并且工作正常。但是,当我将项目根文件夹移动到另一个目录时,似乎会出现此问题。
我完全被困在这里,非常感谢您的所有帮助和反馈。
这是由于 STATICFILES_DIRS 配置中的问题 settings.py 文件。
以下是我的settings.py中的配置:
STATIC_URL ='/ static /'
STATIC_ROOT = os.path.join(BASE_DIR,静态)
现在我将此代码更新为:
STATIC_URL ='/ static /'
STATICFILES_DIRS = [
os.path.join(BASE_DIR,静态),
]
每个文件都可以正常加载。
参考
please help me on this docker django configuration for serving static files.
my Django project running on Docker got some issues with delivering static files.
This is my docker.yml configuration details:
web: build: ./web expose: - "8000" links: - postgres:postgres volumes: - ./web:/usr/src/app ports: - "8000:8000" env_file: .env command: python manage.py runserver 0.0.0.0:8000 postgres: image: postgres:latest volumes: - /var/lib/postgresql ports: - "5432:5432"
update
This is the admin static file url will look like :http://developer.com:8000/static/admin/css/base.cssand this is how client static file url looks like:http://developer.com:8000/static/css/base.cssWhere those admin folder in static directory is creator by running django command collectstatic
I have used this setting previously, and was working fine. But when I moved the project root folder to another directory seems have this issue.
I am totally stuck here, many many thanks for all your help and feedback.
This was issue with the STATICFILES_DIRS configuration in the settings.py file.
Following was the configuration in my settings.py:
STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, "static")
Now I updated this code to:
STATIC_URL = '/static/' STATICFILES_DIRS = [ os.path.join(BASE_DIR, "static"), ]
And every files is loading fine.
Reference Link
这篇关于适用于网络静态文件的Docker Django 404,但适用于管理静态文件的Docker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!