Search code examples
djangodjango-2.0

Django {% extends 'home.html' %} does not transfering dynamic content from extended page to new page


Is that possible to see extended dynamic content((link.nameOne,link.nameTwo)) from home.html page on next.html page on By using following code:

home.html

<!doctype html>
<html lang="en">
<head>
</head>
<body>
  <header>
      <ul>
          {% for link in links.all %}
          <li>
            <a href="{{ link.nameOne }}">{{ link.nameTwo }}</a>
          </li>
          {% endfor %}
      </ul>
  </header>
  {% block content %} 
  {% endblock %}
  <footer>
  </footer>
  </html>

nextPage.html

{% extends 'home.html' %}
{% block content %}
  Hello world!
{% endblock %}

Solution

  • Yes, it's possible but you have to send context info to the template with same names.

    see an example below

    def some_view(request):
        context = {'links': links_queryset}
        return render(request, 'nextPage.html', context)