Django Apache/mod_python Admin CSS 没有出现在管理表中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/480665/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 17:12:05  来源:igfitidea点击:

Django Apache/mod_python Admin CSS not appearing with admin tables

windowsdjangoapacheadminmod-python

提问by Harper Shelby

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:

我有 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'm stumped. Is there more code I should have added somewhere?

我难住了。我应该在某处添加更多代码吗?

回答by Harper Shelby

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?

您的 ADMIN_MEDIA_PREFIX 是否存在?它与 MEDIA_URL 不同吗?您是否包含尾部斜杠?Apache 是否被处理以正确提供管理媒体?

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:

默认 Django 配置的管理媒体位于 {Django install dir}/contrib/admin/media。ADMIN_MEDIA_PREFIX 默认为 /media/。所以你需要在你的 Apache 配置中添加这样的东西:

Alias /media/ /path/to/django/contrib/admin/media/

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.

这将告诉 Apache 对 mysite.com/media/css/whatever.css 的请求意味着提供 /path/to/django/contrib/admin/media/css/whatever.css,这应该可以解决您的问题。

回答by Helmut

I used to have the same problem and the following entry in the http.conf worked fine with me:

我曾经遇到过同样的问题,http.conf 中的以下条目对我来说很好用:

<Directory "Path-to-python/Lib/site-packages/django/contrib/admin/media/"> 
    AllowOverride None 
    Options None 
    Order allow,deny 
    Allow from all 
</Directory> 

Alias /media/ "Path-to-Python/Lib/site-packages/django/contrib/admin/media/"

<Location "/mysite/">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE mysite.settings
    PythonOption django.root /mysite
    PythonInterpreter mysite
    PythonDebug On
    PythonPath "['C:/Python/Django/apps'] + sys.path"
</Location>

回答by fastmultiplication

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.

这是我的 django 特定的 apache 配置。请注意,django 处理除媒体之外的站点(位置 /)的每个传入 url,在此处禁用它,并且数据从 django 的媒体目录提供。

<Location "/">
  SetHandler python-program
  PythonHandler django.core.handlers.modpython
  SetEnv DJANGO_SETTINGS_MODULE mysite.settings
  #PythonOption django.root /
  PythonDebug On
  PythonPath "['e:/dj'] + sys.path"
</Location>

Alias /media  e:/dj/django-trunk/django/contrib/admin/media/
<Location "/media">
  SetHandler None
</Location>

回答by duncan

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...

如果您不想让管理媒体使用 /media 目录,您可以指定 ADMIN_MEDIA_PREFIX = 'admin_media',然后从您的网络服务器创建一个链接/别名,将调用重定向到 /admin_media/ 到 /usr/share/pyshared/ django/contrib/admin/media(取决于您的操作系统)用于您的生产服务器...

回答by Swapnil

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

由于这个问题是很久以前的问题,这可能不是一个相关的答案,但我将这些信息用于帮助任何像我一样偶然在这里绊倒的人。从 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/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-files

https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/#serving-the-admin-files

https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/#serving-the-admin-files

Basically it can be setup in 4 steps -

基本上它可以通过 4 个步骤进行设置 -

  1. Set STATIC_ROOT to point to directory which will serve all the static files of your site
  2. Set STATIC_URL for which static content should be served
  3. Run manage.py collectstatic
  4. Configure your webserver to serve requests for STATIC_URL from STATIC_ROOT
  1. 将 STATIC_ROOT 设置为指向将为您站点的所有静态文件提供服务的目录
  2. 设置应为其提供静态内容的 STATIC_URL
  3. 运行 manage.py collectstatic
  4. 配置您的网络服务器以处理来自 STATIC_ROOT 的 STATIC_URL 请求

Same for media files

媒体文件相同