Assuming I have a \'get_item\' view, how do I write the URL pattern for the following php style of URL?
http://example.com/get_item/?id=2&type=foo&co
See this pattern
url(r'^get_item$', get_item)
And your view will look like
def get_item(request):
id = int(request.Get.get('id'))
You just need to change your url pattern to:
(r'^get_item/$', get_item)
And your view code will work. In Django the url pattern matching is used for the actual path not the querystring.
Make your pattern like this:
(r'^get_item/$', get_item)
And in your view:
def get_item(request):
id = int(request.GET.get('id'))
type = request.GET.get('type', 'default')
Though for normal detail views etc. you should put the id/slug in the url and not in the query string! Use the get parameters eg. for filtering a list view, for determining the current page etc...