[Fixed]-How to pass data between django views

37👍

Assuming you’ve activated django.contrib.sessions.middleware.SessionMiddleware; you can pass data between views using request.session dictionary as follows:

def update_project_filter(request):
    ...
    selected_project_id = project_form.cleaned_data["Project_Name"].id
    request.session['selected_project_id'] = selected_project_id
    ...

def update_project(request):
    ...
    selected_project_id = request.session.get('selected_project_id')
    ...

Leave a comment