Answer the question
In order to leave comments, you need to log in
How to pass data between templates in django?
There is template A and template B. B is inherited from A. Templates are called by different views, data from the model is transferred to A, how to make this data also inherited? Interested in how to do it right, is it worth using ajax or caching here?
Example:
Шаблон А
{% extends "site_base.html" %}
{% load i18n %}
{% block head_title %}home{% endblock %}
{% block body %}
<div class="row">
<a href="#">
<img class="img-responsive" src={{ my_image}}>
</a>
</div>
<div class="row">
{% for object in objects_list %}
<div class="col-lg-2">
<a href="#" class="">
<img src="{{ object.my_image }}">
</a>
</div>
{% endfor %}
{% block result %}
<p>Hello</p>
{% endblock %}
{% endblock %}
Шаблон Б
{% extends 'a.html' %}
{% load i18n %}
Как надо правильно подгружать картинки из шаблона А?
{% block result %}
<p>Шаблон Б<p>
{% block endblock %}
Answer the question
In order to leave comments, you need to log in
maybe it makes sense to make an included template {%include%}? Write in more detail
Inherit the view, or make a separate function that returns the data needed for both views.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question