[Fixed]-'WSGIRequest' object has no attribute 'flash'

1👍

By default the django HttpRequest object doesn’t have an attribute named flash. That’s why you are getting this error. You can see available attributes here: https://docs.djangoproject.com/en/1.9/ref/request-response/#httprequest-objects

But there’s no reason why you can’t add one.

def first_view(request):
    request.flash = {'message'] : 'Operation succeeded!'}
    return HttpResponseRedirect(reverse(second_view))

def second_view(request):
    try:
        print request.flash['message']                    
        request.flash.keep('message')
    except:
        pass
    return HttpResponseRedirect(reverse(third_view))

But from where your flash.keep comes from i have no idea!! As pointed out by wtower it’s more usual to rely on the django messages framework for this sort of thing.

👤e4c5

Leave a comment