How to get the static files URL in view with Python Django?

Sometimes, we want to get the static files URL in view with Python Django.

In this article, we’ll look at how to get the static files URL in view with Python Django.

How to get the static files URL in view with Python Django?

To get the static files URL in view with Python Django, we can use the static function.

For instance, we write

from django.templatetags.static import static

url = static('x.jpg')

to call static with the file path of the file to return the full URL of the file.

Conclusion

To get the static files URL in view with Python Django, we can use the static function.