1
why not write a filter so you can do this.
<img src="{{ user.profile_picture.search_thumbnail.url|custom_filter }}">
and in the custom_filter you read from the settings.STATIC_URL to return the correct URL the user one is not set.
you could make the filter even shorter like this
<img src="{{ user|user_pic_url }}">
and in the filter pull out the .profile_picture.search_thumbnail.url /checks
0
This is what the static
templatetag does underneath, and you can use it just fine in your own code:
from django.contrib.staticfiles.storage import staticfiles_storage
def static(path):
return staticfiles_storage.url(path)
- [Answer]-Django template tags disrupting css output
- [Answer]-Django Startup script for loading values into tables
- [Answer]-Stale content type prompt deleting all model instances after renaming django model with permissions
- [Answer]-How to proceed after Implementing django tenant schemas
- [Answer]-Django default queryset and widget for ModelForm custom field
Source:stackexchange.com