| 2 | |
| 3 | == Why? == |
| 4 | |
| 5 | But before that, here are some reasons to do it: |
| 6 | |
| 7 | * `{% url '...' %}` template tag does respect `SCRIPT_NAME` but `{% static '...' %}` does not |
| 8 | * `reverse(...)` function does respect `SCRIPT_NAME` but `static(...)` does not |
| 9 | |
| 10 | So the first reason is '''consistency''' inside Django core. |
| 11 | |
| 12 | Of course we shouldn't modify `STATIC_URL` when it's an ''absolute URL'', with domain & protocol. But if it starts with `/` - it's ''relative'' to our Django project and we need to add `SCRIPT_NAME` prefix. |
| 13 | |
| 14 | == Real life example == |
| 15 | |
| 16 | You have Django running via WSGI behind reverse proxy (let's call it ''back-end server''), and another HTTP server on the front (let's call it ''front-end server''). Front-end server URL is `http://some.domain.com/sub/path/`, back-end server URL is `http://1.2.3.4:5678/`. You want them both to work. You pass `SCRIPT_NAME = '/sub/path/'` from front-end server to back-end one. But when you access back-end server directly - there is no `SCRIPT_NAME` passed to WSGI/Django. |
| 17 | |
| 18 | So we cannot ''hard-code'' `SCRIPT_NAME` in Django settings because it's dynamic. |