Instagram
youtube
Facebook
Twitter

Django Views

Django Views

Django views are the file where the main logic of a website is present. Django views are responsible for displaying HTML content and error messages on a web page. Use the following method to display views. Also, apply the changes which are given in the Django URLs section.

from Django.shortcuts import render
from Django.shortcuts import HttpResponse

def index(request):
    return HttpResponse("hey! its codersdaily")

The above technique is useful if you want to display HttpResponse on your website. It is not the ideal way to display anything on your website. If you want to render a template then use the following method.

from Django.shortcuts import render
from Django.shortcuts import HttpResponse

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