#19595: The 'redirect' from django.shortcuts does not work in a view function
when
the only parameter is a URL string
-----------------------------+------------------------
Reporter: sergzach | Owner: nobody
Type: Bug | Status: new
Component: Core (URLs) | Version: 1.5-beta-1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------
The fragment of urls.py:
{{{
urlpatterns = patterns('',
# Examples:
url(r'^$', 'home.views.home', name='home'),
url(r'^viewer', 'home.views.viewer', name='viewer'),
...
# Uncomment the next line to enable the admin:
# url(r'^admin/', include(admin.site.urls)),
)
}}}
The home/views.py:
{{{
...
def viewer( request ):
from django.shortcuts import redirect
return redirect( '/' )
...
}}}
I tested the redirect in another similar project, in both cases the
traceback is similar:
{{{
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in
get_response
115. response = callback(request,
*callback_args, **callback_kwargs)
File "C:\cygwin\home\sergzach\lads\lads\views.py" in response
14. request, result = view( *args, **kwargs )
File "C:\cygwin\home\sergzach\lads\home\views.py" in viewer
106. return redirect( '/' )
File "C:\Python27\lib\site-packages\django\shortcuts\__init__.py" in
redirect
70. return redirect_class(resolve_url(to, *args, **kwargs))
File "C:\Python27\lib\site-packages\django\shortcuts\__init__.py" in
resolve_url
143. return urlresolvers.reverse(to, args=args, kwargs=kwargs)
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in
reverse
496. return iri_to_uri(resolver._reverse_with_prefix(view, prefix,
*args, **kwargs))
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in
_reverse_with_prefix
382. possibilities = self.reverse_dict.getlist(lookup_view)
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in
reverse_dict
297. self._populate()
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in
_populate
286. lookups.appendlist(pattern.callback, (bits,
p_pattern, pattern.default_args))
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in
callback
230. self._callback = get_callable(self._callback_str)
File "C:\Python27\lib\site-packages\django\utils\functional.py" in wrapper
29. result = func(*args)
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in
get_callable
92. mod_name, func_name = get_mod_func(lookup_view)
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in
get_mod_func
142. dot = callback.rindex('.')
Exception Type: AttributeError at /viewer/
Exception Value: 'TemplateView' object has no attribute 'rindex'
}}}
The function worked in Django-1.3 (I updated from Django-1.3 or some
release of Django-1.4). In current releases Django-1.4.3 and Django-1.5c1
it does not work as expected.
[The
docs](https://docs.djangoproject.com/en/1.5/topics/http/shortcuts/#django.shortcuts.redirect)
says we could pass the string URL as the first parameter.
--
Ticket URL: <https://code.djangoproject.com/ticket/19595>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.