[Answer]-Resolve Static URL on Server

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)

Leave a comment