Re: Passing optional URL params to reverse() function
Hi Malcolm, Thanks for your answer. Somehow I had a shortcircuit in my brain yerterday that made me try to do an impossible upon the framework, that is, using the same GET response with the same URL after an HTTP redirect, rendering extra information if extra params in the URLconf url were given. I finally realized that this was just impossible -- the one and only ways to pass info into an HTTP request is via GET or POST params, or extra HEADers -- but anyway I am a passionate spirit and sometimes I am blinded. H. On Aug 11, 3:41 am, Malcolm Tredinnickwrote: > On Mon, 2009-08-10 at 11:28 -0700, nabucosound wrote: > > Hi all: > > > I have a URLconf url entry like this: > > > url( > > regex=r'^(?P\w+)/(?P[-\w]+)/$', > > view='show_post', > > name='show_post', > > kwargs={'msg': None}, > > ), > > > and I want to call it with HttpResponseRedirect and reverse(): > > > filters = {'category': post.category.name, 'slug': post.slug} > > return HttpResponseRedirect(reverse('show_post', kwargs=filters)) > > > but I am getting this error: > > > NoReverseMatch at /commentposted/first-post/ > > > Reverse for 'show_post' with arguments '()' and keyword arguments > > '{'category': u'django', 'msg': 'Your comment has been posted', > > 'slug': u'first-post'}' not found. > > [...] > > > Is there any way to pass th reverse() function extra optional > > parameters that the url define? Or am I crazy? > > No, you can't do that. By the way, the extra arguments you are passing > in aren't *optional* -- they are simply not required. There is not > situation in which they will be used to construct the URL. > > You can only pass in parameters that are present in the URL pattern. > There are a bunch of technical reasons for this (including handling > optional arguments and precise error reporting), so it's not an > arbitrary decision. > > Regards, > Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Passing optional URL params to reverse() function
On Mon, 2009-08-10 at 11:28 -0700, nabucosound wrote: > Hi all: > > I have a URLconf url entry like this: > > > url( > regex=r'^(?P\w+)/(?P[-\w]+)/$', > view='show_post', > name='show_post', > kwargs={'msg': None}, > ), > > > and I want to call it with HttpResponseRedirect and reverse(): > > > filters = {'category': post.category.name, 'slug': post.slug} > return HttpResponseRedirect(reverse('show_post', kwargs=filters)) > > > but I am getting this error: > > > NoReverseMatch at /commentposted/first-post/ > > Reverse for 'show_post' with arguments '()' and keyword arguments > '{'category': u'django', 'msg': 'Your comment has been posted', > 'slug': u'first-post'}' not found. > [...] > Is there any way to pass th reverse() function extra optional > parameters that the url define? Or am I crazy? No, you can't do that. By the way, the extra arguments you are passing in aren't *optional* -- they are simply not required. There is not situation in which they will be used to construct the URL. You can only pass in parameters that are present in the URL pattern. There are a bunch of technical reasons for this (including handling optional arguments and precise error reporting), so it's not an arbitrary decision. Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Passing optional URL params to reverse() function
Hi all: I have a URLconf url entry like this: url( regex=r'^(?P\w+)/(?P[-\w]+)/$', view='show_post', name='show_post', kwargs={'msg': None}, ), and I want to call it with HttpResponseRedirect and reverse(): filters = {'category': post.category.name, 'slug': post.slug, 'msg': msg} return HttpResponseRedirect(reverse('show_post', kwargs=filters)) but I am getting this error: NoReverseMatch at /commentposted/first-post/ Reverse for 'show_post' with arguments '()' and keyword arguments '{'category': u'django', 'msg': 'Your comment has been posted', 'slug': u'first-post'}' not found. Request Method: GET Request URL:http://localhost:8000/commentposted/first-post/?c=8 Exception Type: NoReverseMatch Exception Value: Reverse for 'show_post' with arguments '()' and keyword arguments '{'category': u'django', 'msg': 'Your comment has been posted', 'slug': u'first-post'}' not found. Is there any way to pass th reverse() function extra optional parameters that the url define (msg param in this case)? Or am I crazy? Thanks in advance! Hector --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Passing optional URL params to reverse() function
Hi all: I have a URLconf url entry like this: url( regex=r'^(?P\w+)/(?P[-\w]+)/$', view='show_post', name='show_post', kwargs={'msg': None}, ), and I want to call it with HttpResponseRedirect and reverse(): filters = {'category': post.category.name, 'slug': post.slug} return HttpResponseRedirect(reverse('show_post', kwargs=filters)) but I am getting this error: NoReverseMatch at /commentposted/first-post/ Reverse for 'show_post' with arguments '()' and keyword arguments '{'category': u'django', 'msg': 'Your comment has been posted', 'slug': u'first-post'}' not found. Request Method: GET Request URL:http://localhost:8000/commentposted/first-post/?c=8 Exception Type: NoReverseMatch Exception Value: Reverse for 'show_post' with arguments '()' and keyword arguments '{'category': u'django', 'msg': 'Your comment has been posted', 'slug': u'first-post'}' not found. Is there any way to pass th reverse() function extra optional parameters that the url define? Or am I crazy? Thanks in advance! Hector --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---