What Django renders do

environment

Python3.6.2 Django3.0.5

Conclusion

In Function-based views, pass the value of context to template to complete the HTML. A type of rendering.

What is rendering in the first place?

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)

What is render in Django?

To generate HTML from the information defined in View (or obtained from model) using render (by passing context (information) to template).

render method

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.

in conclusion

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

What Django renders do
What is Django? .. ..
Do Django with CodeStar (Python3.6.8, Django2.2.9)
Wai "Can Django do JOIN?"
Do AES encryption with DJango
What to do when "Invalid HTTP_HOST header" appears in Django
What to do when Ubuntu crashes
What to do if yum breaks
Django
What to do with PYTHON release?
What to do to get tensorflow-gpu to work
Django: What to do if TemplateDoesNotExist at / admin / after setting templates
Python | What you can do with Python
How to do arithmetic with Django template
What do you roughly say "sudo su"?
What you can do with API vol.1
Data analysis, what do you do after all?
What is a dog? Django installation volume
How to do Server-Sent Events in Django
What to do after installing Linux (Ubuntu)
Let's summarize what you want to do.
What to do if Django can't load an image from a static folder