bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/Django/Django Tutorial
Django•Django Tutorial

Django Views

Views

Django views are Python functions that take http requests and return http response, like HTML documents.

A web page that uses Django is full of views with different tasks and missions.

Views are usually put in a file called views.py located on your app's folder.

There is a views.py in your members folder that looks like this:

my_tennis_club/members/views.py :

from django.shortcuts import render
# Create your views here.

Find it and open it, and replace the content with this:

my_tennis_club/members/views.py :

from django.shortcuts import render
from django.http import HttpResponse
def members(request):
 return HttpResponse("Hello world!")

Note

The name of the view does not have to be the same as the application.

I call it members because I think it fits well in this context.

This is a simple example on how to send a response back to the browser.

But how can we execute the view? Well, we must call the view via a URL.

You will learn about URLs in the next chapter .

Previous

Django Create App

Next

Django URLs

This chapter

Overview
15

Lessons

36m

Read time

1. Django Tutorial2. Django Introduction3. Django Getting Started4. Django - Create Virtual Environment5. Install Django6. Django Create Project7. Django Create App8. Django Views9. Django URLs10. Django Templates11. Django Models12. Django Insert Data13. Django Update Data14. Django Delete Data15. Django Update Model