Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First, on behalf of my several teams where we've been using drf_spectacular - a huge thank you to @tfranzel and all the other contributors for developing this project.
I noticed that the idea of template tags in
swagger_ui.html
is not new and has already been brought up in this pull request. I read the comments there, and would like to address @tfranzel 's issues raised there:That is not correct. Defining e.g.
{% block body %}
in the template does not change the way the template is rendered, but instead it enables accessing and overriding this block in any template that extends the original template (see Django docs on template inheritance). What really matters is that instead of overriding the entire template it allows for extending it.That is a perfectly valid point. What feels more robust to me is just enclosing the entire
head
andbody
tags in django template tags. This way, any content can be added at the beginning or at the end of these tags. I also think it's safe to say that any further customization should indeed be solved by completely overriding the template.So here's my proposition to add two basic template tags to the
swagger_ui.html
template:{% block head %} {% endblock %}
{% block body %} {% endblock %}
Which allows to:
<body>
<head>
For example:
And why is extending the template better than overriding it? Because in case anything changes in the original template, these changes won't be lost when extending the template, and they are when completely overriding it.
Also introducing a docs mention about it.
Looking forward to see what you think. Have a great day!