As I am learning about how Django handles static files, I have seen two different ways of serving static files while still allowing portability.
One way is to do the following in the template:
{% load static from staticfiles %} <img src="{% static "images/hi.jpg" %}" alt="Hi!" />
as documented here on the Django docs.
The other way I see is to load the context processor for static files, and then use
<img src="{{ STATIC_URL }}images/hi.jpg" alt="Hi!" />
as noted here on the Django docs. When using this method, I change
STATIC_URL
based onif DEBUG: STATIC_URL = 'localhost' else: STATIC_URL = 'some_static_server_url'
Which is considered better practice? Is one way better than the other? For example, this SO question has both methods as answers, and this one has the second method. Any insights would be helpful.