eugene
eugene

Reputation: 41755

specify staticfiles to be loaded in every django template?

Is there a way to do {% load staticfiles %} automatically in every template file?
Would it significantly affect performance?

If it's a bad practice, I wonder if the following use-case is ok.
I'm *include*ing a file in a loop, and loading staticfiles,

{% for a in a_list %}
  {% include "a.html" %}
{% endfor %}

a.html

{% load staticfiles %}
use {% static "a.html" %}

Upvotes: 1

Views: 167

Answers (1)

Timmy O'Mahony
Timmy O'Mahony

Reputation: 53998

You can have the static tag automatically loaded into the set of default tag available in a template using the add_to_builtins method from template.base:

from django.template.base import add_to_builtins
add_to_buildins('django.templatetag.static')

This code would probably be best placed in your settings.py file, or anywhere else that gets imported automatically.

Upvotes: 3

Related Questions