0

I have a few functions in the view.py in my Django project:

Here is the views.py and urls.py under polls:

polls/views.py

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


def index(request):
    return HttpResponse("Hello, world. You're at the polls index.")

def search(request):
    return HttpResponse("You're at the polls search.")

polls/urls.py

from django.urls import path

from . import views
from django.conf.urls import  include, url

urlpatterns = [
    path('', views.index, name='index'),
    path('', views.search, name='search'),
]

I am able to get the index page, but have trouble to reach the page in the search function. I got the error below:

enter image description here

How do I access the search function in the views.py? Thanks!

1
  • What do you mean by your starting page? What is the URL you go to when you get this error? Commented Aug 15, 2018 at 21:54

1 Answer 1

1

edit your polls/urls.py as below:

urlpatterns = [
    path('', views.index, name='index'),
    path('search/', views.search, name='search'),
]

the first argument of the path is the url pattern.

I think you misunderstood the third argument(name). it has nothing to do with the url pattern, it's a name for the url, that'll be useful for url reversing. read the document for more information

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.