Re: question about "\d" in url pattern
thank you very much On 2012/02/28, at 0:37, Justin Myers wrote: > On Feb 27, 1:44 am, Masklinn wrote: >> On 27 févr. 2012, at 07:23, Zheng Li wrote: >>> i thought "\d+" in url promises i can get an int point in cheer_confirm, >>> and am i wrong? >> >> \d+ ensures you will only get naturals, but django will not perform any >> conversion automatically. Especially not here as it would require >> introspecting the regular expression to see which pattern was matched and >> whether it is convertible. > > This is also in the docs: > https://docs.djangoproject.com/en/1.3/topics/http/urls/#notes-on-capturing-text-in-urls > > -- > 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. > -- 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: question about "\d" in url pattern
On Feb 27, 1:44 am, Masklinn wrote: > On 27 févr. 2012, at 07:23, Zheng Li wrote: > > i thought "\d+" in url promises i can get an int point in cheer_confirm, > > and am i wrong? > > \d+ ensures you will only get naturals, but django will not perform any > conversion automatically. Especially not here as it would require > introspecting the regular expression to see which pattern was matched and > whether it is convertible. This is also in the docs: https://docs.djangoproject.com/en/1.3/topics/http/urls/#notes-on-capturing-text-in-urls -- 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: question about "\d" in url pattern
On 27 févr. 2012, at 07:23, Zheng Li wrote: > url(r'^friend_page/cheer/confirm/(?P\w+)/(?P\d+)/(?P\d+)/$', > 'cheer_confirm', name = 'friend_page'), > > def cheer_confirm(request, fid, key, point): > data = { > 'point' : 10 + point, > } > ... > > i got > TypeError: unsupported operand type(s) for +: 'int' and 'unicode' > > i did "print type(point)", and got type(unicode) > apparently, point is not int. > > i thought "\d+" in url promises i can get an int point in cheer_confirm, and > am i wrong? \d+ ensures you will only get naturals, but django will not perform any conversion automatically. Especially not here as it would require introspecting the regular expression to see which pattern was matched and whether it is convertible. -- 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.
question about "\d" in url pattern
url(r'^friend_page/cheer/confirm/(?P\w+)/(?P\d+)/(?P\d+)/$', 'cheer_confirm', name = 'friend_page'), def cheer_confirm(request, fid, key, point): data = { 'point' : 10 + point, } ... i got TypeError: unsupported operand type(s) for +: 'int' and 'unicode' i did "print type(point)", and got type(unicode) apparently, point is not int. i thought "\d+" in url promises i can get an int point in cheer_confirm, and am i wrong? -- 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.