2👍
You can use the template tag in python code, like this:
from django.templatetags.static import static
full_path = static('img/my_img.png')
This will also take into account use cases where the full static path is not simply the concatenation of settings.STATIC_URL with the relative path. See for instance this example in Django documentation.
1👍
You can always import the settings file
from django.conf import settings
...
if my.condition:
return ("<img src='%s/img/my_img.png' />" % (settings.STATIC_URL)) + obj.nam
👤rjv
- [Django]-<title> {% block title %} Home {% endblock %} </title> is not override by other page?
- [Django]-How to run a series of manage.py commands in Django?
- [Django]-How to use date based views in Django
- [Django]-Django auto logout and page redirection
- [Django]-Django CMS plugin context vs. page context
Source:stackexchange.com