Using variables across django templates

Viewed 16

I have a link in a layout template that another template extends. i want the link to pass in a variable thats in the template that extends the other. I want to pass the name variable in the documentPage template through the editDoc link in the layout template. can anyone think of a way to do this? thanks template with the variable template with the link

1 Answers

In views.py file, you can pass the link as a context dictionary to template:

def function_name(request):
    generated_link = 'generated_link'
    context = {
       'link': generated_link 
    }
    return render(request,"documentPage.html",context=context)

You can extends template as :

{% extends 'layout.html' %}
{% block body %}

 # Write body here
 <a href="{{link}}">Click Me</a>

{% endblock %}
Related