Django Apache/mod_python 管理 CSS 未与管理表一起出现
我的 Windows XP/Django/apache/mod_python 在本地主机上运行。 除了管理 CSS 不渲染之外,所有部分都正常工作。 管理员可以工作,但没有 html 格式。 我做了补充:
settings.py
INSTALLED_APPS
'django.contrib.admin',
urls.py
from django.contrib import admin
admin.autodiscover()
(r'^admin/(.*)', admin.site.root),
conf/http.conf
<Location "/">
SetHandler python-program
PythonPath "['C:/django'] + sys.path"
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonDebug On
</Location>
<Location "/cpssite/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE myapplication.settings
PythonInterpreter /myapplication
PythonDebug On
</Location>
我被难住了。 我应该在某处添加更多代码吗?
I have Windows XP/Django/apache/mod_python working on localhost. All parts are working with the exception of the admin CSS not rendering. The admin works, but no html formatting. I've made additions in:
settings.py
INSTALLED_APPS
'django.contrib.admin',
urls.py
from django.contrib import admin
admin.autodiscover()
(r'^admin/(.*)', admin.site.root),
conf/http.conf
<Location "/">
SetHandler python-program
PythonPath "['C:/django'] + sys.path"
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonDebug On
</Location>
<Location "/cpssite/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE myapplication.settings
PythonInterpreter /myapplication
PythonDebug On
</Location>
I'm stumped. Is there more code I should have added somewhere?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您的 ADMIN_MEDIA_PREFIX 存在吗? 它与 MEDIA_URL 有什么不同吗? 您是否包含尾部斜杠? Apache 是否经过处理以正确提供管理媒体?
默认 Django 配置的管理媒体位于 {Django install dir}/contrib/admin/media。 ADMIN_MEDIA_PREFIX 默认为 /media/。 所以你需要在你的 Apache 配置中添加这样的内容:
这将告诉 Apache 对 mysite.com/media/css/whatever.css 的请求意味着提供 /path/to/django/contrib/admin/media/css/ whatever.css,这应该可以解决你的问题。
Does your ADMIN_MEDIA_PREFIX exist? Is it different from MEDIA_URL? Did you include the trailing slash? Is Apache handled to correctly serve up the admin media?
The default Django configuration has the admin media located at {Django install dir}/contrib/admin/media. ADMIN_MEDIA_PREFIX defaults to /media/. So you need to add something like this to your Apache config:
This will tell Apache that requests for mysite.com/media/css/whatever.css mean to serve up /path/to/django/contrib/admin/media/css/whatever.css, which should solve your issue.
我曾经遇到过同样的问题,http.conf 中的以下条目对我来说效果很好:
I used to have the same problem and the following entry in the http.conf worked fine with me:
这是我的 django 特定的 apache 配置。 请注意,django 处理该站点(位置 /)的每个传入 url,但媒体除外,媒体被禁用,并且数据从 django 的媒体目录提供。
Here is my django-specific apache configuration. Note, django handles every incoming url to the site (location /) except media, where it's disabled, and the data is served from django's media directory.
如果您不想让管理媒体使用 /media 目录,您可以指定 ADMIN_MEDIA_PREFIX = 'admin_media',然后从您的网络服务器创建一个链接/别名,它将对 /admin_media/ 的调用重定向到 /usr/share/pyshared/生产服务器的 django/contrib/admin/media (取决于您的操作系统)...
If you don't want to have admin media use the /media directory, you can specify ADMIN_MEDIA_PREFIX = 'admin_media', then create a link/alias from your webserver which redirects calls to /admin_media/ to the /usr/share/pyshared/django/contrib/admin/media (depending on your OS) for your production server...
由于这个问题是很久以前的问题,这可能不是一个相关的答案,但我将这些信息提供给那些像我一样碰巧在这里绊倒的人。
从版本 1.4 开始,ADMIN_MEDIA_PREFIX 设置已被弃用。 这里描述了提供版本 >= 1.4 的静态和媒体文件的方法
https://docs.djangoproject.com/en/dev/releases/1.4/#django-contrib-admin
https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/#serving-files
< a href="https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/#serving-the-admin-files" rel="nofollow">https://docs.djangoproject.com /en/dev/howto/deployment/wsgi/modwsgi/#serving-the-admin-files
基本上可以通过 4 个步骤进行设置 -
媒体文件相同
Since the question is from long time back, this may not be a relevant answer but I am putting this information to help anyone who happens to stumble here just like me.
As of version 1.4, ADMIN_MEDIA_PREFIX setting has been deprecated. The ways of serving static and media files with version >= 1.4 are described here
https://docs.djangoproject.com/en/dev/releases/1.4/#django-contrib-admin
https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/#serving-files
https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/#serving-the-admin-files
Basically it can be setup in 4 steps -
Same for media files