1

I used to pass data through django URL while passing #character is not able to pass through urls.py, I am using pattern as

url(r'^pass/(?P<sentence>[\w|\W]*)/$',pass) 

I tried with these pattern also

url(r'^pass/(?P<sentence>[a-zA-Z0-9-/:-?@#{-~!^_\'\[\]*]*)/$',pass) 

Thanks in advance.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343

2 Answers2

3

The "#" character marks inline anchors (links within the same page) in a URL, so the browser will never send it to Django.

For example, if the URL is /something/pass/#test/something-else/ the browser will sent only /something/pass/ to the server. You can try /something/pass/%23test/something-else/ instead, 23 is the hexadecimal ascii code for # - not pretty (ugly by ugly just pass it as a get variable instead).

There is nothing you can do on the Django side - you better avoid characters with special meanings in the URL path when designing your routes - of course it is a matter of taste, but I really think that strings passed in the URL path should be "slugfied" in order to remove any funny character.

Community
  • 1
  • 1
Paulo Scardine
  • 73,447
  • 11
  • 124
  • 153
  • thanks..but while sending with # character data will be broken..whether it is django's format? @Paulo Scardine – Narenthirasamy Ramasamy Oct 15 '13 at 09:10
  • django will never receive a # in the URL path, no matter what you place on urls.py, because the browser will not send it. Just inspect the network panel in chrome debugger or firebug to see what is being sent. – Paulo Scardine Oct 16 '13 at 00:53
0

Browsers won't send the url fragment part (ends with "#") to servers. Why not converting your data to base64 first, then pass the data via url.

RFC 1808 (Relative Uniform Resource Locators) : Note that the fragment identifier (and the "#" that precedes it) is not considered part of the URL. However, since it is commonly used within the same string context as a URL, a parser must be able to recognize the fragment when it is present and set it aside as part of the parsing process.

Leonardo.Z
  • 9,425
  • 3
  • 35
  • 38