5

I have a strange situation here using Django 3.2.8:

When deploying, only one admin template is being ignored (but not if debug == True):

This is my directory after deploying (and before, they are identical):

enter image description here

change_form.html is applied correctly, whilst submit_line.html is not when debug = false.

content of change_form.html:

{% extends "admin/change_form.html" %}
{% load i18n admin_urls %}
{% block inline_field_sets %}
    {% for inline_admin_formset in inline_admin_formsets %}
        {% include inline_admin_formset.opts.template %}
    {% endfor %}
    <h3>
        <p>WARNING!</p> 
    </h3>
{% endblock %}

content of submit_line.html:

{% load i18n admin_urls %}

<div class="submit-row">
    {% if show_save %}
        <input type="submit" value="{% trans 'Save' %}" class="default" name="_save" />{% endif %}
    {% if show_delete_link %}
        {% url opts|admin_urlname:'delete' original.pk|admin_urlquote as delete_url %}
        <p class="deletelink-box"><a href="{% add_preserved_filters delete_url %}" class="deletelink">{% trans "Delete" %}</a></p>
    {% endif %}
    {% if show_download_zip %}
        <input type="submit" value="{% trans 'zip' %}" name="_download_zip" />
    {% endif %}
    {% if show_save_as_new %}
        <input type="submit" value="{% trans 'Save as new' %}" name="_saveasnew" />
    {% endif %}
    {% if show_save_and_add_another %}
        <input type="submit" value="{% trans 'Save and add another' %}" name="_addanother" />
    {% endif %}
    {% if show_save_and_continue %}
        <input type="submit" value="{% trans 'Save and continue editing' %}" name="_continue" />
    {% endif %}
</div>

pre-deployment, with debug = True: enter image description here compares to: enter image description here

Edit:

A little further digging:

When moving the logic from submit_line.html to change_form.html I get my download button, but only after setting all the buttons visibility by hand - again, this only happens when DEBUG == False:

working render_change_form from admin.py code fragment:

def render_change_form(self, request, context, *args, **kwargs):
    context.update({'show_save_and_add_another': True})
    context.update({'show_save_and_continue': True})
    context.update({'show_save': True})
    context.update({'show_delete_link': True})        
    if not context["original"] == None:
        context.update({'show_download_zip': True})

    return super().render_change_form(request, context, *args, **kwargs)

working change_form.html:

{% block submit_buttons_bottom %}
    {% load i18n admin_urls %}

    <div class="submit-row">
        {% if show_save %}
            <input type="submit" value="{% trans 'Save' %}" class="default" name="_save" />{% endif %}
        {% if show_delete_link %}
            {% url opts|admin_urlname:'delete' original.pk|admin_urlquote as delete_url %}
            <p class="deletelink-box"><a href="{% add_preserved_filters delete_url %}" class="deletelink">{% trans "Delete" %}</a></p>
        {% endif %}
        {% if show_download_zip %}
            <input type="submit" value="{% trans 'zip' %}" name="_download_zip" />
        {% endif %}
        {% if show_save_as_new %}
            <input type="submit" value="{% trans 'Save as new' %}" name="_saveasnew" />
        {% endif %}
        {% if show_save_and_add_another %}
            <input type="submit" value="{% trans 'Save and add another' %}" name="_addanother" />
        {% endif %}
        {% if show_save_and_continue %}
            <input type="submit" value="{% trans 'Save and continue editing' %}" name="_continue" />
        {% endif %}
    </div>
{% endblock %} 

When doing the same in DEBUG == True, the context.update()'s are not needed, also django uses the correct submit_line.html template without any issues.

So ... now I know how to fix this, but I can't figure out why this is happening the way I observed it.

xtlc
  • 1,070
  • 1
  • 15
  • 41

0 Answers0