In your templates, use the static template tag to build the URL for the given relative path using the configured STATICFILES_STORAGE.
{% load static %} <img src="{% static "my_app/example.jpg" %}" alt="My image"/>
Store your static files in a folder called static in your app. For example my_app/static/my_app/example.jpg.
Templates contain standard HTML code (or any other text based content) and template directives, delimited by '{% %}'. They can also contain placeholders, delimited by '{{ }}', which content is processed and replaced with the resulting value. The resulting values are basically the ones you pass using the "template context". You can add filters (after the '|' symbol) for post-processing the value before injecting it in the template.
To answer your precise question, the {% load static %} directive is inserted at the beginning of your HTML template to instruct the templating engine that the static resolution mechanism functions are used.
All this should be clear if you study Django templates documentation and the accompanying examples.
Eric
Templates contain standard HTML code (or any other text based content) and template directives, delimited by '{% %}'. They can also contain placeholders, delimited by '{{ }}', which content is processed and replaced with the resulting value. The resulting values are basically the ones you pass using the "template context". You can add filters (after the '|' symbol) for post-processing the value before injecting it in the template.
To answer your precise question, the {% load static %} directive is inserted at the beginning of your HTML template to instruct the templating engine that the static resolution mechanism functions are used.
All this should be clear if you study Django templates documentation and the accompanying examples.
Eric
From: django...@googlegroups.com <django...@googlegroups.com> on behalf of Avitab Ayan Sarmah <avita...@gmail.com>
Sent: Wednesday, June 6, 2018 6:42:51 PM
To: Django users
Subject: Please give the steps to follow this:
--
In your templates, use the
statictemplate tag to build the URL for the given relative path using the configuredSTATICFILES_STORAGE.{% load static %} <img src="{% static "my_app/example.jpg" %}" alt="My image"/>Store your static files in a folder called
staticin your app. For examplemy_app/static/my_app/example.jpg.
How do i use the static template tag?Because in my templates there is only html files.Where do i add the statement {% load static %}? comment please
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to djang...@googlegroups.com.