Error accessing localhost: 8000 / profile

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>

urls.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')
    )

views.py

from django.shortcuts import render

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

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

Give this error to the page

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.
    
asked by anonymous 13.05.2018 / 22:05

1 answer

1

The problem is that on 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 waiting for something like /perfis/1 or some other number, and you are only accessing with /perfis/ . For that to work, you just need to remove \d+ from that url.

    
14.05.2018 / 20:32