Serve static files with Django without STATIC_URL

94 Views Asked by At

Hi have an application that uses STATIC_URL in the settings. For example:

STATIC_URL = '/static/'

these in url patterns:

url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': settings.MEDIA_ROOT}),

and its usage in a html is like:

<img src="{{STATIC_URL}}images/formshare-computer.png" width="497" height="363"/>

This works if the application is served in http://mydomin.org/ but if I serve it in http://mydomin.org/myapp/ I need to change the STATIC_URL

Is there a way to serve static files without STATIC_URL or how to properly use it in the html?

1

There are 1 best solutions below

1
rafalmp On

From the documentation - in your templates use:

{% load static %}
<img src="{% static 'images/formshare-computer.png' %}" width="497" height="363"/>

MEDIA_* settings have nothing to do with your static content, they are used to manage user-uploaded content.