2012-07-02 67 views
0

我正在尝试做Django教程。第1部分确定(i.stack.imgur.com/US5GN.jpg)一旦我激活管理,在mod_wsgi下的Django找不到其他网址

但是,一旦我激活管理网站,我得到的根(i.stack.imgur.com/EXfE4.jpg)。 编辑(如SO还不允许我发表图片;感谢,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/一次我取消(如指示)抛出这个错误(在我的情况dj1_net/urls.py)行

url(r'^admin/', include(admin.site.urls)), 

mysite/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(谢谢,scytale):

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)), 
) 
+0

你得到的错误是什么? – cberner

+0

我包含纯文本链接,因为我不允许发布图像,但我想这不是一个好主意。我使用代码格式添加了错误。谢谢。 – sadpluto

+0

我刚添加它。顺便说一句,在激活管理员之前,不要改变它“工作”,但现在不行。现在修复urls.py会非常令人费解......谢谢。 – sadpluto

回答

1

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

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

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

+0

糟糕!我想这是教程的第3部分,是吧?我为所有的大惊小怪而感到抱歉。我只是没有想到让管理网站“打破”标准(“它有效”)的回应...谢谢。 – sadpluto

相关问题