#16501: validators.py don't like unicode slug
-------------------------------+------------------------------------
Reporter: norn | Owner: pbnan
Type: New feature | Status: new
Component: Core (Other) | Version: 1.3
Severity: Normal | Resolution:
Keywords: unicode, slug | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Comment (by slikts):
One of the requirements in my app is that I need to have non-English slugs
for use in URLs. This should pose no problem, since modern browsers
support Unicode in URLs, and Django is a framework that supports modern
practices as well, right? So I try to do it, but find out that `SlugField`
only works with ASCII by default. This is mildly annoying, but not really
a problem, since you can just extend `SlugField`, yes? So I look up the
source for `SlugField` and modify the validator regexp like this:
{{{
slug_re = re.compile(r'^[-\w_]+$', re.UNICODE)
validate_slug = RegexValidator(slug_re, "Enter a valid name consisting of
letters, numbers, underscores or hyphens.", 'invalid')
class SlugField(models.SlugField):
default_validators = [validate_slug]
}}}
As it turns out, it just doesn't work, Unicode alphanumerical characters
are still rejected as invalid, and I have not the slightest idea why. A
workaround I found was extending directly from `CharField`, but having to
completely reimplement Django functionality just because I want to use
more than ASCII not very nice at all.
--
Ticket URL: <https://code.djangoproject.com/ticket/16501#comment:15>
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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/062.da62881db7ced4d6cd42897a25a339eb%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.