Articles → DJANGO → Create Our First Function-Based View In Django

Create Our First Function-Based View In Django






What Is Function-Based View?





Create Your First Function-Based View




  1. Go to TestModule folder.
  2. Open views.py and add a new function
  3. from django.http import HttpResponse
    from django.shortcuts import render
    
    # Create your views here.
    def home(request):
      return HttpResponse("Hello")


  4. Go to urls.py (root_folder/urls.py).
  5. Add the following code in urls.py
from django.contrib import admin
from django.urls import path
from TestModule.views import home

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



Output




<python_path>\python manage.py runserver 8080




Picture showing the output of the first function-based view in django
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Sunday, June 9, 2019

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250