andremello
andremello

Reputation: 62

Getting a 404 when trying to access a url python/django

Currently getting a 404 error for my application when I try to access the url /contato, and I am not sure why, can anyone help me?

Here is the error:

Page not found (404)

Request Method: GET

Request URL:    http://localhost:8002/contato

(...)
^contato/
(...)

Here is my code.

My main urls.py has:

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'),)

My contato.urls.py:

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

urlpatterns = patterns('contato.views',
    url(r'^contato/$', 'contato', name="contato"),
)

my 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),)

Upvotes: 0

Views: 274

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599600

You don't have a match for the url "/contato". In your base urls.py, you point the prefix "/contato" to include contato.urls, and then in that file you have a single URL which is again "/contato": so the combined URL for that view is "/contato/contato".

If you just want the URL to match "contato", you should either get the included url to match just "^$", or (probably better) don't bother including the separate urls.py and match the view directly from the base file.

Upvotes: 1

Related Questions