[Django]-How to remove session variable in a template after it's job is done in django

4๐Ÿ‘

โœ…

Do it in the show_dashboard view.

Instead of getting the value from the session in the template, pop it in the view and pass it to the template; that way you take care of getting and clearing it in one go.

@login_required
def show_dashboard(request):
    context = {
        'form': NewArticleForm(),
        'result': request.session.pop('result', None)
    }
    return render(request,'dashboard/dashboard.html',context)

...
{% ifequal result 'add_article_OK' %}
๐Ÿ‘คDaniel Roseman

Leave a comment