Добавил возможность добавить опционально metrics.html
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -176,3 +176,4 @@ cython_debug/
|
||||
|
||||
# Django
|
||||
staticfiles/
|
||||
metrics.html
|
||||
|
||||
13
music_storage/core/templatetags/optional_include.py
Normal file
13
music_storage/core/templatetags/optional_include.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from django import template
|
||||
from django.template.loader import get_template
|
||||
from django.template import TemplateDoesNotExist
|
||||
|
||||
register = template.Library()
|
||||
|
||||
@register.simple_tag(takes_context=True)
|
||||
def include_if_exists(context, template_name):
|
||||
try:
|
||||
tpl = get_template(template_name)
|
||||
return tpl.render(context.flatten())
|
||||
except TemplateDoesNotExist:
|
||||
return ""
|
||||
@@ -24,4 +24,6 @@
|
||||
</div>
|
||||
{% block content_extra %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
{% load optional_include %}
|
||||
{% include_if_exists "metrics.html" %}
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user