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

2 Answers 2

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)
Sign up to request clarification or add additional context in comments.

2 Comments

thanks Chris, what about using %, is there a problem with that?
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.
1

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

1 Comment

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.