Reputation: 33
I have a (what I think) is a pretty basic question about appending a get variable to url in django. I have a filter sidebar on the page which creates a list of available classes based on the selection the user makes in the sidebar. For example, user may click on Aquatics class as a filter(other filters include things like location,price, time of day,etc) it will produce a list of aquatics classes available. Obviously, you can revise the search by choosing a specific location and now it should show a list of aquatics classes in that location. what I would like is to make it so that every time use makes a choice, it adds a get variable to url like so: example.com/search?category=1&location=3. I'm not sure how I should go about it in the template. I know I need to get the list of variables by doing something like this
{% for k, v in request.GET.iteritems %}
{{ k }}={{ v }}&
{% endfor %}
But I dont really know what to do next... Could someone point me in the right direction?
Upvotes: 1
Views: 160
Reputation: 2816
You need to use this. request.GET.urlencode
That code automatically encode your GET parameter into URL friendly.
Upvotes: 1