Python3.6.2 Django3.0.5
In Function-based views, pass the value of context to template to complete the HTML. A type of rendering.
It refers to the generation of images, videos, sounds, etc. using computer programs from abstract, high-order information described in a data description language or data structure. (Source: Wikipedia)
To generate HTML from the information defined in View (or obtained from model) using render (by passing context (information) to template).
The render method takes three main arguments: request, template_name and context.
view.py
def test(request):
context = {{ 'info' :'Pass this' }}
render(request, template_name = test.html, context)
request It consists of session information, call method (GET, POST) information, etc. If this function is called from the outside (HttpRequest), the call information is included. The place to specify the function in the View to call is urls.py.
template_name Specify the destination (html file) to pass the context (info this time) from the template folder.
context Specify the information you want to pass. If it's a dictionary, it doesn't matter if it's not named context.
There are some parts that I do not understand well, so if you have any mistakes or + α, please teach me. If you find this article helpful or happy, please press LGMT.
Recommended Posts