jedierikb
jedierikb

Reputation: 13089

processing urls with hashes like jsbin

jsbin, on browsers which do not support (window.history && window.history.pushState) modify the url via window.location.hash = data.edit; (details here).

This creates urls like this

http://jsbin.com/#/imetor/1/edit

How do I get django's urls.py to process a url like that? I am not even sure that the hash is being sent to the server. If it is not being sent to the server, then what is the technique jsbin uses to pass those parameters to the server?

FWIW, this does not work:

url(r'^#/(?P<project_id>[0-9A-Za-z]{6,})', 'mysite.views.project_hash', name='project_hash'),

Upvotes: 3

Views: 145

Answers (1)

Pierre Drescher
Pierre Drescher

Reputation: 776

You are right. The part past the # does not get sent to the server.

In django, if you want to see the url sent to the server, you can do

print request.get_full_path()

In the case of jsbin, the server returns a page that contains javascript code that then reads the url params and executes code to personalize the page. An example of javascript code that parses a url and executes a function is Backbone.Router (http://backbonejs.org/#Router).

Upvotes: 1

Related Questions