python - Django 静态文件未使用 NGINX 加载
问题描述
我正在尝试使用 NGINX 在生产服务器上发布我的第一个 Django 应用程序。
project
--app1
--app2
--config
settings.py
wsgi.py
urls.py
--venv
manage.py
nginx配置
server {
listen 80;
server_name my_IP_adress;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/websites/testAPP;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
在我的设置中,我有以下代码
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
ROOT_DIR = environ.Path(__file__)
STATIC_URL = '/static/'
STATIC_ROOT = str(ROOT_DIR('statics'))
STATICFILES_DIRS = [
str(BASE_DIR.path('static')),
]
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]
我在 urls.py 中添加了一个
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
但是,当我在生产服务器上运行 collectstatoc 时,我得到了这个错误:
settings.py", line 24, in <module>
str(BASE_DIR.path('static')),
AttributeError: 'str' object has no attribute 'path'
我该如何解决?
解决方案
BASE_DIR 只是一个字符串...字符串没有path
属性...我认为您的意思是
STATICFILES_DIRS = [
os.path.join(BASE_DIR,'static'),
]
推荐阅读
- python - 是否可以将文本渲染为从 qt5 中的图层“剪切”?
- java - 使用 maven 在 zip 中损坏 JARS
- java - Java查找字符串数组的索引并使用该索引来查找另一个数组的值保存该索引
- visual-studio - 如何显示有效的事件处理程序签名
- python - 如何创建具有巨大价值范围的热图?
- c# - asp.net core razor 页面复选框模型绑定(始终为 false)
- sql - 如何在 sqlalchemy 中使用来自两个 sql 表的数据
- r - 从宽格式到长格式的不同时变变量
- java - Java - 通过带有 TCP 客户端的 OBIS 代码读取寄存器值
- ldap - 创建策略时,Keycloak 返回 Resource Not Found