整个这一天,我试图在生产服务器上配置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'),
)
的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>
我不知道出了什么问题。
答案 0 :(得分:2)
不确定这是否会解决您的问题,但在我的site.conf中为django我不得不评论该行:
PythonOption django.root /
让它发挥作用。
答案 1 :(得分:2)
您真的不想使用mod_python进行部署。我强烈建议转向mod_wsgi以获取Django depoyment。
答案 2 :(得分:0)
我只是把它扔到那里,但你必须在你的设置文件中启用django管理中间件。它就在那里,但开箱即用。如果你已经这样做了,我不知道你的问题是什么。