2013-12-18 32 views
0

我在urls.py下面的代碼:Django的URLPATTERN 「不匹配」

urlpatterns = patterns('', 
    (r'^news/', include('news.urls')), 
) 

當我嘗試打開

http://localhost/news 

http://localhost/news/ 

瀏覽器django給我看404頁面:

Using the URLconf defined in python.urls, Django tried these URL patterns, in this order: 

^news/ 

The current URL, , didn't match any of these. 

UPD:

新聞/ urls.py:

from django.conf.urls.defaults import * 
from django.views.generic.simple import direct_to_template 

urlpatterns = patterns('news.views', 
    (r'^$', 'news'), 
) 

有新聞目錄views.py,它包含了新聞的功能。

並將新聞模塊添加到INSTALLED_APPS。

爲什麼找不到新聞模式?有什麼建議麼?

+2

向我們展示你的'news/urls.py'? – greg

+0

'在python.urls中定義的URLconf < - python.urls?真? –

+0

[Django的URL正則表達式引擎失敗]的可能重複(http://stackoverflow.com/questions/18390217/djangos-url-regex-engine-is-failing) –

回答

0

您的應用程序在哪個端口啓動?當我看到你的嘗試http://locahost/news它可能是你忘了使用正確的端口。

嘗試訪問http://localhost:8000/http://localhost:8000/news

+0

我通過manage.py啓動了fastcgi runfcgi host = 127.0.0.1 port = 8080,並且我添加了fastcgi_pass 127.0.0.1:8080;到nginx虛擬主機文件 – Phantom

3

您似乎忘記了url()功能:

試試這個:

from django.conf.urls import url 

urlpatterns = patterns('', 
    url(r'^news/', include('news.urls')), 
) 

和新聞/ urls.py:

from django.conf.urls.defaults import * 
from django.views.generic.simple import direct_to_template 
from django.conf.urls import url 

urlpatterns = patterns('news.views', 
    url(r'^$', 'news'), 
)