找不到Django urls.py

时间:2011-10-18 01:46:54

标签: django django-views django-urls

设置名为OmniCloud_App的Django应用的网址。访问/ OmniCloud_App /注册时未获取URL的获取和错误。这是主要的urls.py:

urlpatterns = patterns('',
  (r'^OmniCloud_App/$', include('OmniCloud_App.urls')),
  (r'^admin/', include(admin.site.urls)),
)

然后包含OmniCloud_App / urls.py:

urlpatterns = patterns('OmniCloud_App.views',
    (r'^', 'home'),
    (r'^signup/', 'signup'),
    (r'^(?P<User_id>\d+)/$', 'profile'),
    (r'^(?P<User_id>\d+)/social$', 'social'),
    (r'^(?P<User_id>\d+)/news$', 'news'),
    (r'^(?P<User_id>\d+)/email$', 'email'),
    (r'^(?P<User_id>\d+)/photos$', 'photos'),
)

所以注册应该转到views.py中的注册方法:

def signup(request):
    return render_to_response('OmniCloud_App/Templates/OmniCloud/signup.html', context_instance=RequestContext(request))

为什么这不起作用?这是404,这意味着它永远不会超过最初的urls.py文件,尽管访问简单/ OmniCloud_App /正确呈现'home'页面(也在include('OmniCloud_App.urls')

中定义)

urls.py 404 page

1 个答案:

答案 0 :(得分:7)

您需要从此处删除$

(r'^OmniCloud_App/$', include('OmniCloud_App.urls')),

所以它是:

(r'^OmniCloud_App/', include('OmniCloud_App.urls')),

$表示字符串的结尾。