python - 在 CPanel 中使用 Python 在 Django 管理面板中加载静态文件
问题描述
我已经使用 CPanel 在我的服务器中设置了一个 Django Python 应用程序。wsgi 配置正确,index.html(没有任何 css)运行正常,但管理面板没有正确加载 css。
我一直在阅读我需要正确设置静态文件路由,但这些似乎都不起作用。
我的 settings.py 文件在已安装的应用程序中有 static 指令,最后这行是我的 python virtualenv 的静态文件所在的位置。
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static') #after collect static is run all the static files will be put in this folder
STATICFILES_DIRS = (['/home/djangouser/virtualenv/api/3.5/lib/python3.5/site-packages/django/contrib/admin/static/admin/'])
我已经尝试重新启动应用程序,但这些都不起作用,我的管理页面仍然在没有 css 的情况下加载。
我的 index.html 没有任何 CSS,所以我不知道这是否只是管理员的问题......但我需要解决这个问题。
谢谢你。
解决方案
完美的解决方案是通过网络服务器提供静态文件。但是您也可以使用 Cling 使用 Python 来完成:
$ pip install dj-static static3
并更新您的 wsgi.py:
...
from dj_static import Cling
...
application = Cling(get_wsgi_application())
推荐阅读
- powershell - 区分 PowerShell 中不同类型的哈希表?
- java - 组件为 HandlerExceptionResolver 扫描一个类
- r - 通过检查多列 R 中的 NA 单元格来创建列
- networking - 虚拟盒子 + vagrant centos8 盒子(无头)从互联网访问
- swift - 如何正确使用 needsInputModeSwitchKey?
- jenkins - conn_id 未在 Airflow JenkinsJobTriggerOperator 中定义
- javascript - 如何在webgl中使用alpha绘制两个纹理
- python - searchpyi.py 的问题 - '用 Python 自动化无聊的东西'
- angular - Nested Observable/Promise (trying to block/wait flow in mapper function)
- java - “circle” Cannot be resolved to a variable