Django Apache/mod_python 管理 CSS 未与管理表一起出现

发布于 2024-07-13 04:27:02 字数 830 浏览 6 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

新一帅帅 2024-07-20 04:27:02

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

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

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

这将告诉 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:

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.

我的黑色迷你裙 2024-07-20 04:27:02

我曾经遇到过同样的问题,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>

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

<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>
烦人精 2024-07-20 04:27:02

这是我的 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>

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.

<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>
夏九 2024-07-20 04:27:02

如果您不想让管理媒体使用 /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...

沫尐诺 2024-07-20 04:27:02

由于这个问题是很久以前的问题,这可能不是一个相关的答案,但我将这些信息提供给那些像我一样碰巧在这里绊倒的人。
从版本 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 个步骤进行设置 -

  1. 设置 STATIC_ROOT 指向将为站点的所有静态文件提供服务的目录
  2. 设置应为其提供静态内容的 STATIC_URL
  3. 运行 manage.pycollectstatic
  4. 配置您的网络服务器以服务来自 STATIC_ROOT 的 STATIC_URL 请求

媒体文件相同

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 -

  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

Same for media files

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文