姜戈 + mod_python + apache:管理面板和 url 不起作用
一整天我都在尝试在生产服务器上配置 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您确实不想使用 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.
我只是把它扔在那里,但你必须在你的设置文件中启用 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.
不确定这是否能解决您的问题,但在 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.