The regular expression you give will only match ACSII letters,  
numbers, and minus (-). If you have anything else, like a space  
orother punctuation, it will fail.

One solution is to use slugify from django.template.defaultfilters. It  
will turn everything into a good slug. Then all you need is to add an  
_ to get (?P<slug>[\-\d\w_]+). If you are not an english speaker, then  
you might look at http://amisphere.com/contrib/python-django/ slugHIFI.

If you don’t want to translate or can’t for whatever reason, Try  
changing the last bit of the regular expression to /(?P<slug>[^/#?]+)/ 
$ and it will match almost anything. Unfortunately, you can’t count on  
anything sent without translation. If you’re careful, you can  
translate it back.

On Apr 29, 2008, at 11:39 AM, chatchai wrote:
>
> Hi,
>
> I'm try to get meaning full url but it seem like I will give up and
> use translate or random ascii instead.
>
> I try to quote slug and got key error because urllib doesn't take care
> about unicode. So I add
> self.slug = quote(self.slug.encode('utf-8')) and it work with some
> case, not all.
>
> I have url like this,
>
> r'^post/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?
> P<slug>[\-\d\w]+)/$'
>
> It work well (with slug.encode) but not all case. I mean, some
> characters produce error.
>
> What is the best way to deal with this thing? Or just use something
> instead (translate slug to ascii, numeric?)
>
> Regards
>
> Chatchai

-- 
Peter of the Norse


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to