在CPanel中使用Python在Django管理控制台中加载静态文件 [英] Load static files in Django Admin panel using Python in CPanel

查看:94
本文介绍了在CPanel中使用Python在Django管理控制台中加载静态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用CPanel在服务器中设置了Django Python应用程序。 wsgi配置正确,index.html(没有任何CSS)运行正常,但管理面板未正确加载CSS。

I have already set up a Django Python application in my server with CPanel. The wsgi is correctly configured, the index.html (which doesn't have any css) runs properly but the admin panel doesn't load correctly the css.

一直在读,我需要正确设置静态文件的路由,这似乎都不起作用。

I have been reading that I need to properly set the static files routes and none of this seems to work.

我的settings.py文件在已安装的应用中具有static指令,因此最后一行是我的python virtualenv静态文件所在的行。

My settings.py file have the static directive in the installed apps and this lines at the end, where my static files of the python virtualenv is.

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的情况下加载。

I have tried restaring the application but none of this work and my admin page still loading without css.

我的index.html没有任何CSS,所以我没有不知道这是否只是管理员的问题...但是我需要来解决这个问题。

My index.html doesn't have any css so I don't know if this is only a problem of the admin... But I need to fix this up.

谢谢。

推荐答案

完美解决方案是通过Web服务器提供静态文件。但是您也可以使用Cling在Python中完成此操作:

The perfect solution is to serve static files via a webserver. But you can also do it with Python using Cling:

$ pip install dj-static static3

并更新您的wsgi.py:

And update your wsgi.py:

...
from dj_static import Cling
...
application = Cling(get_wsgi_application())

这篇关于在CPanel中使用Python在Django管理控制台中加载静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆