姜戈 + mod_python + apache:管理面板和 url 不起作用

发布于 2024-09-10 12:43:39 字数 2232 浏览 11 评论 0原文

一整天我都在尝试在生产服务器上配置 django。我使用mod_python。当我打开 http://beta.example.com 时,我看到了我的网站,但 http://beta.example.com/admin 和 http://beta.example.com/441/abc/ 不起作用:

Page not found (404)
Request Method:     GET
Request URL:    http://beta.example.com/admin

{'path': u'admin'}

You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.


Page not found (404)
Request Method:     GET
Request URL:    http://beta.example.com/441/abc/

{'path': u'441/abc/'}

You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.

我的网址:

from settings import MEDIA_ROOT
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # static files
    url(r'^static/javascripts/(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': MEDIA_ROOT + '/javascripts'}, name='javascripts'),
    url(r'^static/images/(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': MEDIA_ROOT + '/images'}, name='images'),
    url(r'^static/stylesheets/(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': MEDIA_ROOT + '/stylesheets'}, name='stylesheets'),
    url(r'^static/(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': MEDIA_ROOT}, name='static'),
    (r'^admin/', include(admin.site.urls)),
    url(r'^/?$', 'content.views.index', name='root-url'),
    url(r'^(?P<id>[0-9]{2,5})/(?P<slug>[a-z\-]+)/?$', 'content.views.show', name='show-url'),

)

阿帕奇:

DocumentRoot "/var/www/django/beta.example.com/site"

<Location "/">
  allow from all
  SetHandler python-program
  PythonHandler django.core.handlers.modpython
  SetEnv DJANGO_SETTINGS_MODULE site.settings
  PythonOption django.root /
  PythonDebug On
  PythonPath "['/var/www/django/beta.example.com', '/var/www/django/beta.example.com/site'] + sys.path"
</Location>

<Location "/static" >
  SetHandler none
</Location>

我不知道出了什么问题。

Whole this day I was trying to configure django on production server. I use mod_python. When I open http: //beta.example.com I see my site but http: //beta.example.com/admin and http: //beta.example.com/441/abc/ doesn't work:

Page not found (404)
Request Method:     GET
Request URL:    http://beta.example.com/admin

{'path': u'admin'}

You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.


Page not found (404)
Request Method:     GET
Request URL:    http://beta.example.com/441/abc/

{'path': u'441/abc/'}

You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.

My urls:

from settings import MEDIA_ROOT
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # static files
    url(r'^static/javascripts/(?P<path>.*)

Apache:

DocumentRoot "/var/www/django/beta.example.com/site"

<Location "/">
  allow from all
  SetHandler python-program
  PythonHandler django.core.handlers.modpython
  SetEnv DJANGO_SETTINGS_MODULE site.settings
  PythonOption django.root /
  PythonDebug On
  PythonPath "['/var/www/django/beta.example.com', '/var/www/django/beta.example.com/site'] + sys.path"
</Location>

<Location "/static" >
  SetHandler none
</Location>

I have no idea what's wrong.

, 'django.views.static.serve', {'document_root': MEDIA_ROOT + '/javascripts'}, name='javascripts'), url(r'^static/images/(?P<path>.*)

Apache:


I have no idea what's wrong.

, 'django.views.static.serve', {'document_root': MEDIA_ROOT + '/images'}, name='images'), url(r'^static/stylesheets/(?P<path>.*)

Apache:


I have no idea what's wrong.

, 'django.views.static.serve', {'document_root': MEDIA_ROOT + '/stylesheets'}, name='stylesheets'), url(r'^static/(?P<path>.*)

Apache:


I have no idea what's wrong.

, 'django.views.static.serve', {'document_root': MEDIA_ROOT}, name='static'), (r'^admin/', include(admin.site.urls)), url(r'^/?

Apache:


I have no idea what's wrong.

, 'content.views.index', name='root-url'), url(r'^(?P<id>[0-9]{2,5})/(?P<slug>[a-z\-]+)/?

Apache:


I have no idea what's wrong.

, 'content.views.show', name='show-url'), )

Apache:

I have no idea what's wrong.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

厌味 2024-09-17 12:43:40

您确实不想使用 mod_python 进行部署。我强烈建议转向 mod_wsgi 进行 Django 部署。

You really don't want to be using mod_python for deployment. I highly suggest moving to mod_wsgi for Django depoyment.

柠檬色的秋千 2024-09-17 12:43:40

我只是把它扔在那里,但你必须在你的设置文件中启用 django admin 中间件。它就在那里,但开箱即用地注释掉了。如果你这样做了,我不知道你的问题是什么。

I'm just throwing this out there, but you have to enable the django admin middleware in your settings file. It's there but commented out right out of the box. If you've done that I don't have any idea what your problem is.

心奴独伤 2024-09-17 12:43:39

不确定这是否能解决您的问题,但在 django 的 site.conf 中,我必须注释以下行:

PythonOption django.root /

才能使其正常工作。

Not sure if that will solve your problem but in my site.conf for django I had to comment the line:

PythonOption django.root /

to make it work.

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