xtl*_*tlc 5 django-templates django-admin django-staticfiles django-deployment
我使用 Django 3.2.8 遇到了一个奇怪的情况:
部署时,只有一个管理模板被忽略(但不是 if debug == True):
这是我部署后的目录(和之前,它们是相同的):
正确应用了change_form.html,而submit_line.html则不正确debug = false。
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 %}
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
编辑:
进一步挖掘:
当将逻辑从 移动到 时submit_line.html,change_form.html我得到了下载按钮,但只有在手动设置所有按钮可见性之后- 再次,这仅在以下情况下发生DEBUG == False:
render_change_form从admin.py代码片段开始工作:
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)
Run Code Online (Sandbox Code Playgroud)
在职的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 %}
Run Code Online (Sandbox Code Playgroud)
在 中执行相同操作时DEBUG == True,context.update()不需要 ,而且 django 使用正确的submit_line.html模板也没有任何问题。
所以......现在我知道如何解决这个问题,但我无法弄清楚为什么会以我观察到的方式发生这种情况。
| 归档时间: |
|
| 查看次数: |
169 次 |
| 最近记录: |