Home > database >  Django Tutorial. Page not found
Django Tutorial. Page not found

Time:05-18

I already search for any answer which could help me before write this question, but I haven't found anything that helps.

The thing is that I follow the tutorial and I can't see the view that I created.

Now I'm going to share my code:

project urls.py:

from django.contrib import admin
from django.urls import include, path 

urlpatterns = [
    path('polls/', include('polls.urls')),
    path('admin/', admin.site.urls),
]

polls urls.py:

from django.urls import path
from . import views

urlpatterns = [
    path(" ", views.index, name='index'),
    #127.0.0.1/polls/
]

polls views.py

from django.http import HttpResponse
from django.shortcuts import render

# Create your views here.
def index(request):
    HttpResponse("Welcome to de Polls Universe Index")

OK I ALREADY KNOW WHATS GOING ON:

I forgot the RETURN before de HttpResponse.

CodePudding user response:

There are two issues with your code:

  • The path for the index view contains a blank, which must be removed
  • The view function must return a response object. Please add return in front of the last line.
  • Related