RedirectView with query_string = True and urlencoded unicode string

282 views
Skip to first unread message

Slafs

unread,
Aug 11, 2011, 4:35:43 AM8/11/11
to django...@googlegroups.com
Hi there!

I'm having difficulties with the new class based RedirectView with query_string = True and some unicode string in QUERY_STRING.
I made a sample of the error on bitbucket

https://bitbucket.org/slafs/redirectviewtest/src

could You please explain what I'm doing wrong? or maybe it is a bug in a redirect view ?
I've read the docs about the "%" sign in urls but I think this behaviour should not apply to args (query_string)

Regards

Sławek

Daniel Roseman

unread,
Aug 11, 2011, 4:39:26 AM8/11/11
to django...@googlegroups.com
You neglected to tell us what the error was, or show the traceback.
--
DR. 

Slafs

unread,
Aug 11, 2011, 4:59:24 AM8/11/11
to django...@googlegroups.com
Oh sorry. Here it is

http://dpaste.com/591903/

File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py" in get_redirect_url
  146.             return url % kwargs

Exception Type: ValueError at /test/
Exception Value: unsupported format character 'C' (0x43) at index 15

Slafs

unread,
Aug 11, 2011, 10:48:37 AM8/11/11
to django...@googlegroups.com
Should i report a ticket?

Karen Tracey

unread,
Aug 13, 2011, 12:47:30 AM8/13/11
to django...@googlegroups.com
On Thu, Aug 11, 2011 at 10:48 AM, Slafs <sla...@gmail.com> wrote:
Should i report a ticket?

Yes please, that's a bug in Django.

Karen
--
http://tracey.org/kmt/

Germán

unread,
May 14, 2012, 5:19:14 PM5/14/12
to django...@googlegroups.com
Hi. Please excuse my ignorance in this affairs.

For an specific URI, I have the following error
Traceback (most recent call last): 
 
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 111, in get_response
   response = callback(request, *callback_args, **callback_kwargs)

 File "/usr/local/lib/python2.6/dist-packages/django/views/generic/base.py", line 47, in view
   return self.dispatch(request, *args, **kwargs)

 File "/usr/local/lib/python2.6/dist-packages/django/views/generic/base.py", line 68, in dispatch
   return handler(request, *args, **kwargs)

 File "/usr/local/lib/python2.6/dist-packages/django/views/generic/base.py", line 151, in get
   url = self.get_redirect_url(**kwargs)

 File "/usr/local/lib/python2.6/dist-packages/django/views/generic/base.py", line 146, in get_redirect_url
   return url % kwargs

TypeError: not enough arguments for format string

The version I use is 1.3.1, and the urls.py line determining the redirection is
(r'^planes/((?P<anything>.*))', RedirectView.as_view(url='/tmovil/planes/%(anything)s', query_string=True)),

Is it possible the bug reported in ticket 16842 is cause for this error? If not, should I file a bug?

Thanks

On Saturday, August 13, 2011 12:47:30 AM UTC-4, Karen Tracey wrote:

Sławek Ehlert

unread,
May 14, 2012, 5:30:45 PM5/14/12
to django...@googlegroups.com, Germán
As the error states:
You don't have a format argument in your
'/tmovil/planes/%(anything)s' string.

Cheers
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/SebYILZBuMAJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Andrew Bruce

unread,
May 14, 2012, 7:10:10 PM5/14/12
to django...@googlegroups.com
You have passed 'anything' as a keyword argument that will get passed into your view. Unfortunately, you can't access it in your inline constructor call. Try subclassing RedirectView in views.py of your app.

class SubRedirectView(RedirectView):

    query_string = True

    def get_redirect_url(self, **kwargs):
        return '/tmovil/planes/%s' % self.kwargs.get('anything', None)

~Drew

German Larrain M.

unread,
May 15, 2012, 10:33:13 AM5/15/12
to django...@googlegroups.com
Andrew,

What bothers me is that the redirection setup works perfectly for any value of "anything" or querystring; it only fails for this specific case.

How is that possible?

Thanks again
--
Germán Larraín M.
Reply all
Reply to author
Forward
0 new messages