Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

178
Visualizações
Django which template to extends with if block

I have two distincts template which must be extended in three diffrents page. Is there a solution to extends a template with if block? I tried this without success.

{% if 'project' in request.get_full_path %}
  {% extends 'index.html' %}

{% elif 'network' in request.get_full_path %}
  {% extends 'base.html' %}

{% elif 'zoneset' in request.get_full_path %}
  {% extends 'base.html' %}

{% endif %}

{% load crispy_forms_tags %}

{% block title %} Network {% endblock title %}

{% block content %}

<div class="row">
  <div class="col-md">
    <div class="card card-body">
      <h6>Update</h6>
      <form class="" action="" method="post" enctype="multipart/form-data">
        {% csrf_token %}
          {{form|crispy}}
        <input type="submit" name="" value="Update">
      </form>
    </div>
  </div>
</div>
{% endblock %}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

If you work with template inheritance, {% extends … %} [Django-doc] should be the first template tag. You can not use an {% if … %} block, nor is it a good idea to detect the parent based on the full path of the request.

You can do this in the view, and work with:

def my_view(request):
    context = { 'parent': 'index.html' }
    return render(request, 'my_template.html', context)

and then in the template use:

{% extends parent %}
…
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda