[Django] #16734: urlresolvers doesn't get a script prefix from manage.py

40 views
Skip to first unread message

Django

unread,
Aug 30, 2011, 10:27:20 PM8/30/11
to django-...@googlegroups.com
#16734: urlresolvers doesn't get a script prefix from manage.py
-------------------+--------------------------------------------
Reporter: d00gs | Owner: nobody
Type: Bug | Status: new
Milestone: | Component: Core (Management commands)
Version: 1.3 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------+--------------------------------------------
The script prefix for `django.core.urlresolvers` doesn't get set to
anything when being called through `manage.py`, because of course it
doesn't know what that value should be. This is a problem if you're
rendering views (or otherwise reversing urls) from a `manage.py` command
(as one of my sites does to send emails).

This is solvable by calling `set_script_prefix` from `settings.py`, but
that feels kind of dirty since it's then about to be rewritten in the WSGI
handler.

I don't know what a good solution to this would be. Perhaps it would be
nice to be able to set a global default script path somewhere that would
then get incorporated into the default values of things like LOGIN_URL.

Maybe just a note in the documentation would be good. It took me a while
to figure out, because I haven't been able to find anything else about
this online. (I guess that non-`/` script paths are uncommon and reversing
urls from `manage.py` is also uncommon, so both together are very
uncommon.)

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

Django

unread,
Sep 4, 2011, 5:05:36 PM9/4/11
to django-...@googlegroups.com
#16734: urlresolvers doesn't get a script prefix from manage.py
-------------------------------------+-------------------------------------
Reporter: d00gs | Owner: nobody
Type: Bug | Status: new
Milestone: | Component: Core (Management
Version: 1.3 | commands)
Resolution: | Severity: Normal
Triage Stage: Accepted | Keywords:
Needs documentation: 0 | Has patch: 0
Patch needs improvement: 0 | Needs tests: 0
UI/UX: 0 | Easy pickings: 0
-------------------------------------+-------------------------------------
Changes (by aaugustin):

* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0


Comment:

Based on code inspection, I confirm that this bug exists.

Possible fix: `django.core.management.setup_environ` could do something
along the lines of:

{{{
from django.conf import settings
from django.core.management.base import set_script_prefix
from django.utils.encoding import force_unicode

set_script_prefix(u'/' if settings.FORCE_SCRIPT_NAME is None else
force_unicode(settings.FORCE_SCRIPT_NAME))
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/16734#comment:1>

Django

unread,
Dec 12, 2013, 7:06:52 AM12/12/13
to django-...@googlegroups.com
#16734: urlresolvers doesn't get a script prefix from manage.py
-------------------------------------+-------------------------------------

Reporter: d00gs | Owner: nobody
Type: Bug | Status: new
Component: Core (Management | Version: 1.3
commands) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by julen):

* cc: julenx@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/16734#comment:2>

Django

unread,
Apr 2, 2014, 1:07:00 PM4/2/14
to django-...@googlegroups.com
#16734: urlresolvers doesn't get a script prefix from manage.py
-------------------------------------+-------------------------------------

Reporter: d00gs | Owner: nobody
Type: Bug | Status: new
Component: Core (Management | Version: 1.3
commands) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by AkosLadanyi):

* cc: AkosLadanyi (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/16734#comment:3>

Django

unread,
Apr 2, 2014, 3:50:30 PM4/2/14
to django-...@googlegroups.com
#16734: urlresolvers doesn't get a script prefix from manage.py
-------------------------------------+-------------------------------------

Reporter: d00gs | Owner: nobody
Type: Bug | Status: new
Component: Core (Management | Version: 1.3
commands) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by AkosLadanyi):

If it is not possible to figure out the value of script_prefix in all
cases (like in manage.py) why not just store its value in a settings
variable? Then reverse could just prepend this value to all paths deduced
from urlconf.

--
Ticket URL: <https://code.djangoproject.com/ticket/16734#comment:4>

Django

unread,
May 6, 2015, 8:18:25 AM5/6/15
to django-...@googlegroups.com
#16734: urlresolvers doesn't get a script prefix from manage.py
-------------------------------------+-------------------------------------

Reporter: d00gs | Owner: nobody
Type: Bug | Status: new
Component: Core (Management | Version: 1.3
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by julen):

Would it make sense to call `set_script_prefix()` in `ManagementUtility`'s
`execute()` method,
[https://github.com/django/django/blob/4dcc6493418c78db07761180bf6265f5b2bbccbf/django/core/management/__init__.py#L303
once settings have been configured]?

--
Ticket URL: <https://code.djangoproject.com/ticket/16734#comment:5>

Django

unread,
May 6, 2015, 8:34:44 AM5/6/15
to django-...@googlegroups.com
#16734: urlresolvers doesn't get a script prefix from manage.py
-------------------------------------+-------------------------------------

Reporter: d00gs | Owner: nobody
Type: Bug | Status: new
Component: Core (Management | Version: 1.3
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timgraham):

`django.setup()` seems to be a natural place for it.

--
Ticket URL: <https://code.djangoproject.com/ticket/16734#comment:6>

Django

unread,
May 6, 2015, 9:09:14 AM5/6/15
to django-...@googlegroups.com
#16734: urlresolvers doesn't get a script prefix from manage.py
-------------------------------------+-------------------------------------

Reporter: d00gs | Owner: nobody
Type: Bug | Status: new
Component: Core (Management | Version: 1.3
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by julen):

I thought so initially, but this issue is limited to management commands,
that's why I wonder about `ManagementUtility.execute()`. Once the right
location for this is confirmed, the fix should be trivial.

--
Ticket URL: <https://code.djangoproject.com/ticket/16734#comment:7>

Django

unread,
May 6, 2015, 9:13:35 AM5/6/15
to django-...@googlegroups.com
#16734: urlresolvers doesn't get a script prefix from manage.py
-------------------------------------+-------------------------------------

Reporter: d00gs | Owner: nobody
Type: Bug | Status: new
Component: Core (Management | Version: 1.3
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timgraham):

I imagine it would also affect standalone scripts that invoke
`django.setup()` but don't use `ManagementUtility`.

--
Ticket URL: <https://code.djangoproject.com/ticket/16734#comment:8>

Django

unread,
Oct 23, 2015, 3:21:34 PM10/23/15
to django-...@googlegroups.com
#16734: urlresolvers doesn't get a script prefix from manage.py
-------------------------------------+-------------------------------------

Reporter: d00gs | Owner: nobody
Type: Bug | Status: new
Component: Core (Management | Version: master

commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by claudep):

* needs_docs: 0 => 1
* has_patch: 0 => 1
* version: 1.3 => master


--
Ticket URL: <https://code.djangoproject.com/ticket/16734#comment:9>

Django

unread,
Oct 27, 2015, 3:13:26 PM10/27/15
to django-...@googlegroups.com
#16734: urlresolvers doesn't get a script prefix from manage.py
-------------------------------------+-------------------------------------

Reporter: d00gs | Owner: nobody
Type: Bug | Status: new
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by claudep):

* needs_docs: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/16734#comment:10>

Django

unread,
Oct 27, 2015, 8:13:30 PM10/27/15
to django-...@googlegroups.com
#16734: Set script prefix in django.setup() to allow its usage outside of requests
-------------------------------------+-------------------------------------
Reporter: d00gs | Owner: nobody
Type: New feature | Status: new

Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* type: Bug => New feature
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/16734#comment:11>

Django

unread,
Oct 29, 2015, 3:13:26 PM10/29/15
to django-...@googlegroups.com
#16734: Set script prefix in django.setup() to allow its usage outside of requests
-------------------------------------+-------------------------------------
Reporter: d00gs | Owner: nobody
Type: New feature | Status: closed

Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz <claude@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"7d81ee6efc385f7d4c1218639e4102c64495ba0f" 7d81ee6e]:
{{{
#!CommitTicketReference repository=""
revision="7d81ee6efc385f7d4c1218639e4102c64495ba0f"
Fixed #16734 -- Set script prefix even outside of requests

Thanks Tim Graham for the review.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/16734#comment:12>

Reply all
Reply to author
Forward
0 new messages