{% if check %}
//do stuff related to view2
{% else %}
//do stuff related to view1 %}
{%endif%}
Problem :
This is just a question to know about Django. I have two views and I am rendering two contexts to two views.How can I render both the contexts to the same HTML template?
Comments
Comment posted by Sri Test
and how do I add them in urls.py?
Comment posted by Sri Test
and how do I add them in urls.py?Actually I get a problem that I could access only one of the variable in jinja template.One of them doesnt show up any value @bolino
Comment posted by bolino
Just put two “path” or “re_path” in your urls.py, calling each of your views. About the template, it doesn’t need to use all the variables in the context, so you can use only part of them if you want to.
Comment posted by Sri Test
Could you specify an example of above mentioned comment? @bolino
Comment posted by bolino
e.g.
Comment posted by Sri Test
but I already have a dictionary coming from another class which doesn’t have any flags like check
Comment posted by Sri Test
but I already have a dictionary coming from another class which doesn’t have any flags like check
Comment posted by Abhishek bansal
In that case, you can use bolino’s answer if the keys are same, and values are different. However, if keys are also different check whether they are null, and if not then do stuff.
Comment posted by Sri Test
no my keys are different.Why do I have to use a condition.Can’t I directly reference the variable in the HTML file? @Abhishek
Comment posted by Abhishek bansal
@Sri Test Yes you can directly refer them but for someone else reading the code in your template, it won’t make much sense as to what thing is coming from which view. Although I am not understanding what exactly you want to ask here?