0

Is there a problem with using unicode (hebrew specificaly) strings including white space.

some of them also include characters such as "%" .

I'm experiencing some problems and since this is my first Django project I want to rule out this as a problem before going further into debugging.

And if there is a known Django problem with this kind of urls is there a way around it?

I know I can reformat the text to solve some of those problems but since I'm preparing a site that uses raw open government data sets (perfectly legal) I would like to stick to the original format as possible.

thanks for the help

alonisser
  • 11,542
  • 21
  • 85
  • 139

2 Answers2

1

Take a look here for a fairly comprehensive discussion on what makes an invalid (or valid) URL.

Community
  • 1
  • 1
Pep_8_Guardiola
  • 5,002
  • 1
  • 24
  • 35
  • this is a fairly comprehensive question about url, but my question is not about valid url's but about Django url variables.. a little different isn't it? – alonisser Jun 14 '12 at 18:27
1

Django shouldn't have any problems with unicode URLs, or whitespace in URLs for that matter (although you might want to take care to make sure whitespace is urlecoded (%20).

Either way, though, using white space in a URL is just bad form. It's not guaranteed to work unless it's urlencoded, and then that's just one more thing to worry about. Best to make any field that will eventually become part of a URL a SlugField (so spaces aren't allowed to begin with) or run the value through slugify before placing it in the URL:

In template:

http://domain.com/{{ some_string_with_spaces|slugify }}/

Or in python code:

from django.template.defaultfilters import slugify

u'http://domain.com/%s/' % slugify(some_string_with_spaces)
Chris Pratt
  • 232,153
  • 36
  • 385
  • 444
  • thanks Chris, what about using %, is there a problem with that? – alonisser Jun 14 '12 at 21:38
  • Not unless you're running it through some sort string interpolation (like my python code use of `slugify` for example). Then, in just the string part (i.e. not the variables being passed in), you need to escape it by prefixing another `%`. For example, `%%` will end up as just `%` after string interpolation. – Chris Pratt Jun 14 '12 at 21:45