Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Django urls.py to recognize # (hash) in url?

Let's say I want the following url to get matched with a django view through urls.py: www.mysite.com/cake/#vanilla

In urls.py I have something like this:

url('^cake/#.*/$', app.views.view ),

So basically I want all urls that start with root: www.mysite.com/cake/#, to be handled by this view. However, django urls seems to treats # as %23, so instead all urls with root www.mysite.com/cake/%23 is handled by that view. How can I get the hash sign in url('^cake/#.*/$', app.views.view ), to be treated like an actual hash sign instead of a %23?

Thanks for any help!

like image 585
killajoule Avatar asked Jan 19 '12 19:01

killajoule


People also ask

How does urls py work in Django?

A request in Django first comes to urls.py and then goes to the matching function in views.py. Python functions in views.py take the web request from urls.py and give the web response to templates. It may go to the data access layer in models.py as per the queryset.

How will Django match urls?

Django runs through each URL pattern, in order, and stops at the first one that matches the requested URL, matching against path_info . Once one of the URL patterns matches, Django imports and calls the given view, which is a Python function (or a class-based view).

How do I add a URL to a Django project?

project/urls.py is the one that django uses, so you have to import to project/urls.py. Which means, that you have to state your imports in project/urls.py. The imported urls.py file must also define a valid urlconf, named urlpatterns. I think I had to restart the server (plus forgot the include), works now!


1 Answers

You need to force your users to use IE7 from winetricks. It's the only browser that has the bug of sending the hash and stuff in the HTTP request :)

If it has been fixed, then you need to force your users to use IE7 from winetricks of last year's version.

As Adam stated, browsers should not send the hash part to the server. Using the hash in the url is common for websites like deezer because it lets the user navigate without reloading the page (all navigation is handled in javascript). This allows navigation without interuption/reload of the music player which is in flash.

If you want to enable hash browsing, then you can use a plugin like: http://tkyk.github.com/jquery-history-plugin/

like image 153
jpic Avatar answered Sep 23 '22 10:09

jpic