#34028: Django 'static' template tag fails to generate URLs with SCRIPT_NAME 
prefix
---------------------------------+--------------------------------------
     Reporter:  Stewart Adam     |                    Owner:  nobody
         Type:  Bug              |                   Status:  closed
    Component:  Template system  |                  Version:  4.0
     Severity:  Normal           |               Resolution:  worksforme
     Keywords:                   |             Triage Stage:  Unreviewed
    Has patch:  0                |      Needs documentation:  0
  Needs tests:  0                |  Patch needs improvement:  0
Easy pickings:  0                |                    UI/UX:  0
---------------------------------+--------------------------------------

Comment (by Florian Apolloner):

 Setting a custom script name also works:

 {{{
 #!python
 from django.urls.base import *
 set_script_prefix('/lala')
 from django.template import engines
 django_engine = engines['django']
 from django.conf import settings
 print(settings.FORCE_SCRIPT_NAME)
 print(settings.STATIC_URL) # Note: in settings.py it is 'static/' but the
 output here will include FORCE_SCRIPT_NAME
 print(django_engine.from_string("{% load static %}{% static 'test_file'
 %}").render())
 }}}

 {{{
 None
 /lala/static/
 /lala/static/test_file
 }}}

 That said it is true that the value of `SCRIPT_NAME` is assumed to be
 static and not change over the runtime of Django. If Django is "loaded"
 outside of a webcontext first, then you will see the behavior you are
 describing. I'll accept the ticket for now but I am not sure if this is
 fixable easily or at all.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34028#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701836ee74fdd-2b90a10f-258b-4b8a-981f-0dd3a0e592ac-000000%40eu-central-1.amazonses.com.

Reply via email to