tags:

views:

36

answers:

2

How do I pass a query string from a response, meantime the relative template should also get loaded.

ex:

http://www.domain.com/test/?id=23423424

and id=23423424 is a key that is saved in the DB, so need to attach this when processing the response.

Thanks.

+1  A: 

use request.GET.get('id') to get the ID form the query string.

dotty
+1  A: 

To my understanding, there are two ways to do this. You can either do it in urls.py (and views.py, but that comes later) or in views.py.

In views.py:

def your_view(request):
    id = request.GET.get('id', None)
    ## The rest of your view.

In urls.py:

urlpatterns = patterns('',
    (r'^test/\?id=(?P<id>\d+)$', 'path.to.your_view', {}, "your_view_name"),
)

View for urls.py method:

def your_view(request, id):
    ## The rest of your view.
Jack M.