ray smith
ray smith

Reputation: 380

How to pass around variables without url parameters in Django?

My question is, how could I go about passing information in django from the template to a view without url parameters. I know that sessions can help me do this however, I can't find any resources online that show how to create a key value pair in the sessions from within a template. For example, If I had a link

<a href= "{% url .....%}">{{ c.class_id }}</a>

which would lead you to a specific university class homepage, how could I pass along c.class_id to the view that is responsible for rendering this specific homepage? Would I have to put this link inside a form and then POST it to the view?

Upvotes: 0

Views: 2702

Answers (1)

aumo
aumo

Reputation: 5574

You can use GET parameters. Example:

<a href= "{% url .....%}?class_id={{c.class_id}}">{{ c.class_id }}</a>

To retrieve the parameter from the Django view, use:

param_value = request.GET['param_name']

Upvotes: 4

Related Questions