Django. Cancel button for form in admin site
Is there any functionality in admin site that allow to implement for every add/change form cancel button, that redirects me to list of that for开发者_Python百科m objects. I mean some general solution for any form.
Add admin/submit_line.html
in your project's templates
directory. Use the code from the default submit_line.html, and add your cancel button. You can link it to just "../" to make it always just go up one level. Then do any necessary CSS styling to make it look right.
Create a file: yourapp/templates/admin/submit_line.html
I use Bootstrap, but you can change this easily
{% extends "admin/submit_line.html" %}
{% block submit-row %}
{{ block.super }}
<a href="../../" class="btn btn-secondary" style="color: white">Cancel</a>
{% endblock %}
Be sure that your application is above "admin" in INSTALLED_APPS.
Looks like this in German locale:
<a href="{% url opts|admin_urlname:'changelist' %}"><input type="button" name="Cancel" value="Cancel"></a>
You can this line anywhere inside admin/submit_line.html
精彩评论