Django and query string parameters -


assuming have 'get_item' view, how write url pattern following php style of url?

http://example.com/get_item/?id=2&type=foo&color=bar 

(i not using standard 'nice' type of url ie: http://example.com/get_item/2/foo/bar not practical)

specifically, how make make view respond when user types above in browser, , how collect parameters , use in view?

i tried @ least id part right no avail. view won't run when type in browser http://example.com/get_item?id=2

my url pattern:

(r'^get_item/id(?p<id>\d+)$', get_item) 

my view:

def get_item(request):     id = request.get.get('id', none)     xxxxxx 

in short, how implement php's style of url pattern query string parameters in django?

make pattern this:

(r'^get_item/$', get_item) 

and in view:

def get_item(request):     id = int(request.get.get('id'))     type = request.get.get('type', 'default') 

though normal detail views etc. should put id/slug in url , not in query string! use parameters eg. filtering list view, determining current page etc...


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -