I am new to django. I came across the include()
method. I read the documentation regarding it. But couldn't understand it as it lacked suitable examples. I am again rewriting this question in a proper way so that it doesn't sound baseless. Can someone please help me out by giving me a suitable example regarding the scenario in which the include()
method becomes handy?
The include tag allows you include a template inside the current template. This is useful when you have a block of content that are the same for many pages.
From django document, include() function was described as follows. Whenever Django encounters include(), it chops off whatever part of the URL matched up to that point and sends the remaining string to the included URLconf for further processing.
include tag loads a template and renders it with the current context. This is a way of “including” other templates within a template. The template name can either be a variable or a hard-coded (quoted) string, in either single or double quotes.
reverse_lazy()providing a reversed URL as the url attribute of a generic class-based view. providing a reversed URL to a decorator (such as the login_url argument for the django.
include()
adds urls from your app directory's urls.py
to the main urls.py (in memory). This keeps the main urls.py from getting too big to read.
see https://docs.djangoproject.com/en/2.2/topics/http/urls/
The Including Other URLConfs section.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With