0

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?

QLands
  • 2,424
  • 5
  • 30
  • 50

1 Answers1

0

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.

rafalmp
  • 3,988
  • 3
  • 28
  • 34
  • That returns the same as STATIC_URL. If the Django application is running using WSGI in for example http://localhost/myapp/ then if you use /static/ does not exists. – QLands Jul 29 '16 at 08:16