The views function
expresses the functions of views through the effect of views on urls, templates and models
① (matching url): The urls file matches the corresponding URL, and the specified function is searched for URL processing, and this processing function is included in the views file. Medium
② (template and data transfer): The various ways of writing templates in django make the front-end display more flexible, which often requires the back-end control function to transfer a large amount of data. After the function in the Views file matches the corresponding URL, it will decide which template to use and what parameters to pass to the template
③ (data interaction): Data interaction is the most important part of the back-end function. The Views file is introduced into the model module, which can perform database operation functions such as data filtering, analysis and extraction. In addition, the views file can also obtain front-end requests, obtain form data for comparison and analysis, and insert into the database. For example, ajax sends a POST request to operate the database.
(Data interaction)-----implemented Django's control layer and presentation layer
views use functions to interact with fields defined in models, respond and logically control page requests, and the representation of page content is provided by Django's Template. template (HTML) to complete.
Django's View can be understood as a python function that implements various functions. Views is responsible for accepting the URL defined in the URL configuration file urls.py to forward and respond to processing. When Django receives the request, it calls the corresponding views function to complete
all views of the function. All functions need to take the request object as the first parameter. The request is an instance object of HttpRequest, that is, the request class HttpRequest object, which contains the user's request information; when the page is accessed, it is the one you set in urls.py When the matching address matches; the request will be created
from django.http import HttpResponse //HttpResponse is a class, http is a package, and django is a module def hello(request): //return HttpResponse object return HttpResponse("Hello world")
Python accumulation:
(python various type conversions----------int, str, char, float, ord, hex, oct, etc.)
int() converts x to an integer
long() converts x to a long
float() converts x to a float
complex() creates a complex
str() converts an object x to a string
repr() converts an object x to an expression string
eval() is used to evaluate the string a valid Python expression in , and returns an object
tuple() converts a sequence s to a tuple
list() converts a sequence s to a list
chr() converts an integer to a character
unichr() converts an integer to Unicode character
ord() Converts a character to its integer value
hex() Converts an integer to a hexadecimal string
oct() Converts an integer to an octal string