当我尝试访问url / contato时,我的应用程序出现404错误,我不知道为什么,有人可以帮助我吗?
这是错误:
Page not found (404)
Request Method: GET
Request URL: http://localhost:8002/contato
(...)
^contato/
(...)
这是我的代码。
我的主要urls.py有:
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.contrib import admin
urlpatterns = patterns('',
url(r'^admin/password_reset/$', 'django.contrib.auth.views.password_reset', name='admin_password_reset'),
url(r'^admin/password_reset/done/$', 'django.contrib.auth.views.password_reset_done'),
url(r'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$', 'django.contrib.auth.views.password_reset_confirm'),
url(r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete'),
url(r'^admin/', include(admin.site.urls)),
url(r'^perfil/', include('perfil.urls')),
url(r'^contato/', include('contato.urls')),
url(r'^$', 'views.index', name='index'),)
我的contato.urls.py:
from django.conf.urls.defaults import patterns, url
urlpatterns = patterns('contato.views',
url(r'^contato/$', 'contato', name="contato"),
)
我的views.py in contato:
from django.shortcuts import render_to_response
from django.template import RequestContext
def contato(request):
render_to_response('contato/contato.html',locals(),context_instance=RequestContext(request),)
答案 0 :(得分:1)
您没有匹配网址&#34; / contato&#34;。在你的基础urls.py中,你指出前缀&#34; / contato&#34;要包含contato.urls,然后在该文件中你有一个URL再次&#34; / contato&#34;:所以该视图的组合URL是&#34; / contato / contato&#34;。< / p>
如果您只是希望网址与&#34; contato&#34;相匹配,则您应该获得包含的网址,以便仅匹配&#34; ^ $&#34;或者(可能更好)don&#39;打扰包括单独的urls.py并直接从基本文件匹配视图。