Since you are trying to get this data from a completed form, I think the easiest way is to pass the .cleaned_data forms to the template and use this. Let's say you have a form with the name and specialty fields, it will look something like this:
def my_view(request): form = my_form(request.GET) if form.is_valid(): ... do search stuff ... search_query = form.cleaned_data return render_to_response('my_template.html', {'search_query': search_query, 'search_results': ...,}, ...)
Then in your template, you simply pull out the desired values:
<tr> <th>Name</th> <th>Specialty</td> </tr> <tr> <td>{{ search_query.name }}</td> <td>{{ search_query.specialty }}</th> </tr>
Or you format it for Excel.
source share