#31724: django.urls.resolve ignores the FORCE_SCRIPT_NAME setting.
-------------------------------+--------------------------------------
     Reporter:  Pēteris Caune  |                    Owner:  nobody
         Type:  Bug            |                   Status:  closed
    Component:  Core (URLs)    |                  Version:  3.0
     Severity:  Normal         |               Resolution:  invalid
     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):

 Replying to [comment:4 Pēteris Caune]:
 > Perhaps the documentation should mention that `reverse` will obey
 `FORCE_SCRIPT_NAME` but `resolve` won't?
 Documentation updates will never hurt. Do you feel up to the task? :)

 > My use case: I'm using `resolve` for whitelisting redirect URLs. In my
 app, the login page can take a `?next=some-url` GET parameter, and after
 the user logs in, they get redirected to `some-url`. I wanted to have a
 whitelist of what redirect targets are allowed. So I'm passing `some-url`
 to `resolve` and am looking if the `ResolverMatch.url_name` is in my
 whitelist.  Does this seem like a reasonable use case for `resolve`?

 It does, but sadly is not something that is achievable easily as of now, I
 am sorry :( I agree that it is unfortunate that `resolve` behaves like it
 does, but it makes a little bit more sense with the
 `SCRIPT_NAME`/`PATH_INFO` differences from above. If Django were to pass
 `SCRIPT_NAME + PATH_INFO` to `resolve` then the urlpatterns would have to
 include `SCRIPT_NAME` and as such would no longer be portable. As far as
 Django is concerned it is rooted below `SCRIPT_NAME`. Given how html links
 work the only sensible option for `reverse` is to generate a path absolute
 URL which requires it to append the `SCRIPT_NAME`. It would be even worse
 if Django supported hosting on multiple subdomains, then `reverse` would
 most likely have to generate full URLs including domains ;)

 As for your issue at hand, I think the easiest solution is to check if
 your URL starts with `SCRIPT_NAME/FORCE_SCRIPT_NAME` and then cut that
 off.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31724#comment:5>
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/064.6e8b5fc64cdf8771ec2f454c33f41a34%40djangoproject.com.

Reply via email to