Categories
Python Answers

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

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *