0

i have certain variables in my request.GET which are like product-21cad54c-fafe-11dd-9f2b-001b639ca120, product-11cvcfd1-fafe-11dd-9f2b-001b639ca120, (the id is part of the variable name)

I want to store the id's of all these product variables, how can i retrieve these ids seperately?

1
  • if this is part of the url - use (r'^product-(?P<id>.+)', 'my_view'), then in views: def my_view(request, id): Commented Apr 6, 2011 at 9:30

1 Answer 1

4

In your view, you can treat request.GET a bit like a dict. You can use:

request.GET.keys()

In the case of a url with the form: http://foo/?bar=baz&bing=boom, you would get ['bar','bing'].

Is this what you are trying to do?

[After comment]

In that case, you should be able to:

for key in request.GET.keys():
    if key.startswith('product-'):
        the_id = key.split('-',0)[1]
        # Do some processing with the_id now…
Sign up to request clarification or add additional context in comments.

1 Comment

The name of my keys are product-21cad54c-fafe-11dd-9f2b-001b639ca120, product-11cvcfd1-fafe-11dd-9f2b-001b639ca120, The product part is fixed while the id after the - changes. when i retrieving this request i want to be able to segregate the id part of these product variables and store them in a database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.