Azad Rasul




4- Write a view

Azad Rasul's photo
Azad Rasul
·May 7, 2022·

1 min read

Play this article

Open the file polls/ For example, we open "Sublime Text" software. From File>New Folder> we select: PollProject folder

Then put the following Python code in polls/

from django.http import HttpResponse

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

To call the view, we need to map it to a URL.

In the polls directory, create a file called select: polls>right click> New File> Save as>

In the polls/ file include the following code:

from django.urls import path

from . import views

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

Then open: PollProject/ and past the following code in it: ``` from django.contrib import admin from django.urls import include, path

urlpatterns = [ path('polls/', include('polls.urls')), path('admin/',, ] Verify it’s working with the following command: py runserver ```

Then, go to localhost:8000/polls in your browser.

If you like the content, please SUBSCRIBE to my channel for the future content

Share this