Display query string values in django templates
these are the default context processors: https://docs.djangoproject.com/en/dev/ref/templates/api/#using-requestcontext
TEMPLATES = [ {"OPTIONS": { "context_processors": [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
]}}]
if its not in your settings than you haven't overridden it yet. do that now.
then in your template, something like this:
{% if request.GET.q %}<div>{{ request.GET.q }}</div>{% endif %}
also, I'm noticing in your link url you are not using a querystring operator, ?
. You should be:
return HttpResponseRedirect("/mysite/?q="+successfailure)
I'm not sure I understand the question, but you can access the querystring in your view with request.GET
.
So you could adjust the view that renders home.html by adding the successfailure variable into the context. Something like -
def home_view(request):
#....
successfailure = request.GET
return render(request, 'home.html', {'succsessfailure': successfailure.iteritems()})
Then iterate throught the variables in your template
{% for key, value in successfailure %}
<p>{{ key }} {{ value }}</p>
{% endfor %}
If there's a specific key in the querystring you can get the value with request.GET['your_key']
and drop the call to iteritems()
(along with the iteration in the template).