Error accessing localhost:8000/profile

Asked

Viewed 205 times

0

page profiles.html

<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="utf-8">
    <title>ConnectedIn</title>
</head>
<body>
    <h1>Detalhe Perfil</h1>

</body>
</html>

py.

from django.conf.urls import patterns, include, url
from django.contrib import admin

urlpatterns = patterns ('',
    url(r'^$', 'perfis.views.index'),
    url(r'^perfis/\d+$', 'perfis.views.exibir')
    )

py views.

from django.shortcuts import render

def index(request):
    return render(request, 'index.html')

def exibir(request):
    return render(request, 'perfil.html')

Give that page error

P

age not found (404)
Request Method: GET
Request URL:    http://localhost:8000/perfil
Using the URLconf defined in connectedin.urls, Django tried these URL patterns, in this order:

^admin/
^$
The current URL, perfil, didn't match any of these.

You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
  • It also seems that you own the template with the name perfis.html and in the view called the perfil.html.

1 answer

1


The problem is that in your urls.py you are mapping your view to a different URL than the one you are accessing. See:

urlpatterns = patterns ('',
    url(r'^$', 'perfis.views.index'),
    url(r'^perfis/\d+$', 'perfis.views.exibir')  # <- aqui
)

On that line Django will be expecting something like /perfis/1 or some other number, and you are accessing only with /perfis/. For it to work, you just need to remove the \d+ of that url.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.