开发者

Django: # in url as a character?

开发者 https://www.devze.com 2022-12-16 02:18 出处:网络
I\'ve made a Django application that uses tags. When i use tag \'c#\' and try to redirect to mysiteaddress/tags/c# on server it redirects to ../tags/c and shows me stuff connected to \'c\' tag, but wh

I've made a Django application that uses tags. When i use tag 'c#' and try to redirect to mysiteaddress/tags/c# on server it redirects to ../tags/c and shows me stuff connected to 'c' tag, but when I do the same on my local development machine it redirects me to c%23 and works correctly. What should I change to mak开发者_如何学JAVAe it work on production server?


Without more code I can't be too specific, but '#' corresponds to the character escape sequence %23 and something in your code may need to explicitly escape 'c#' before putting it in the url.

Here is a django-snippet that uses url-quoting:

http://www.djangosnippets.org/snippets/1159/

The solution to your problem might look like this:

from django.utils.http import urlquote
...
tag = urlquote(tag)
tag_url = base + "tags/" + tag
...
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号