[Django]-Django HttpResponseRedirect pass variable to template and read it

5👍

You could pass GET variables:

/mytemplate?variable1="variable_1"

You can also use the messages framework

from django.contrib import messages

def view(request):
  # your code
  messages.error(request, "ERROR")
  HttpResponseRedirect("/mytemplate")

or maybe you can add a session

def view(request):
    request.session['error'] = "ERROR"
    return HttpResponseRedirect("/mytemplate")


def my_template(request):
        if request.session.has_key('error'):
           error = request.session.get('error')
           del request.session['error']
        return render(request, "myTemplate.html", locals())

Leave a comment