Opened 4 years ago

Last modified 4 years ago

#31724 closed Bug

django.urls.resolve ignores the FORCE_SCRIPT_NAME setting — at Version 1

Reported by: Pēteris Caune Owned by: nobody
Component: Core (URLs) Version: 3.0
Severity: Normal Keywords:
Cc: Florian Apolloner Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Pēteris Caune)

I suspect the django.urls.resolve function is not taking in account the FORCE_SCRIPT_NAME setting.

First, with FORCE_SCRIPT_NAME=None, I can do the following in manage.py shell:

>>> from django.urls import resolve, reverse
>>> reverse("hc-docs")
'/docs/'
>>> resolve(reverse("hc-docs"))
ResolverMatch(func=hc.front.views.serve_doc, args=(), kwargs={}, url_name=hc-docs, app_names=[], namespaces=[], route=docs/)

In the above example, I can feed the result of reverse back into resolve and it works as expected.

Now with FORCE_SCRIPT_NAME='/foo':

>>> from django.urls import resolve, reverse
>>> reverse("hc-docs")
'/foo/docs/'
>>> resolve(reverse("hc-docs"))
Traceback (most recent call last):
(...)
    raise Resolver404({'tried': tried, 'path': new_path})

Here, reverse added the "/foo" prefix to the URL, but resolve didn't seem to recognize it.

I suspect this is a bug but not sure. How is django.urls.resolve expected to behave here?

Change History (1)

comment:1 by Pēteris Caune, 4 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top