一旦我激活管理员,mod_wsgi下的Django找不到其他URL

时间:2012-07-02 17:25:59

标签: django mod-wsgi

我正在尝试使用Django教程。第1部分没问题(i.stack.imgur.com/US5GN.jpg)

但是,一旦我激活管理站点,我就会获得根目录(i.stack.imgur.com/EXfE4.jpg)。 修改(因为S.O.还不允许我发布图片;谢谢,cberner):

Page not found (404)
Request Method:     GET
Request URL:        http://dj1.net/
Using the URLconf defined in dj1_net.urls, Django tried these URL patterns, in this order:
^admin/
The current URL, , didn't match any of these.

dj1.net是我的测试域(正在编辑/etc/hosts),而dj1.net/admin/现在按预期工作,我不知道为什么dj1.net/在我取消注释后会抛出此错误(按照指示)行

url(r'^admin/', include(admin.site.urls)),
mysite/urls.py下的

(在我的情况下为dj1_net/urls.py)。在我看来,除非 GET请求针对/admin/,否则一切都应该像以前一样工作

我的堆栈:Apache和mod_wsgi的Debian 6.0 VPS。 我想避免使用Django的内置服务器:如果我不能将其部署为真实的,我宁愿早点而不是稍后知道。事实上,为了方便PHP支持,我对基于Apache的解决方案非常感兴趣。

如需进一步参考,请参阅我的/etc/apache2/sites-available/dj1.net

<VirtualHost *:80>
    ServerName dj1.net
    DocumentRoot /var/www/dj1_net
    Alias /static/ /var/www/dj1_net/static/
    Alias /media/ /var/www/dj1_net/media/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    WSGIScriptAlias / /var/www/dj1_net/django.wsgi
    WSGIProcessGroup dj1_net
    WSGIDaemonProcess dj1_net processes=2 threads=16 maximum-requests=1000 display-name=apache-dj1_net-wsgi
</VirtualHost>

最后,这里是/var/www/dj1_net/django.wsgi

import sys
import os
import os.path
sys.path.append(os.path.dirname(__file__))
os.environ['DJANGO_SETTINGS_MODULE'] = 'dj1_net.settings'
from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()

为了提前做好准备,我知道Apache服务器配置 WSGI接近于零。但是,我确实希望在开始使用Django之前完成这项设置工作。我跟着the official instructionsthis post的混合,因为我坦率地说不能让Django逐字地应用任何一条指令。我担心问题的根源必定就在那里......

任何提示将不胜感激。

干杯!

S.P。

第二次修改。这是dj1_net/urls.py(谢谢,狡猾):

from django.conf.urls import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'dj1_net.views.home', name='home'),
    # url(r'^dj1_net/', include('dj1_net.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
)

1 个答案:

答案 0 :(得分:1)

您没有为网站的根目录定义网址。您需要添加一个,例如:

url(r'^$', 'dj1_net.views.my_view_function'),

这将在定义管理URL的行之后。