Django: Send Context To 'base.html'
I have a nav bar item that is used to register/login. As, it's gonna be in different pages, I'm thinking of calling this form 'once' for every page, in the 'base.html'. I've found
Solution 1:
You should replace return context
with return render(request, 'PATH/TEMPLATE.html', context)
.
This also resolves your question which template it renders :-)
Solution 2:
To have a navbar template in your base.html, create templates/myapp/navbar.html
and then in your
base.html
...
include('myapp/navbar.html')
...
If you want to show the user name you can add in your navbar.html
{% if request.user.is_authenticated %}
{{ request.user.username }}
{% endif %}
If you want to add other data to your navbar, use context processors.
Use TemplateView
in your view to define wich template to use:
from django.views.generic import TemplateView
classRegistroClienteView(TemplateView):
template_name = 'myapp/my_template.html'
...
Finally as stated in my comment:
You can set any url you want, as long as you pass the view. as in
url(r'^any-url-i-want/$', RegistroClienteView.as_view(), name='any-name-i-want'),
Post a Comment for "Django: Send Context To 'base.html'"