I have following scenario.

1. User fills out a form
2. If the user clicks the "continue" button and the form is valid the user will be redirected to a summary view
3. In the summary view the user checks the input again. He can either continue or go back.
4. If he continues the data will be saved in the database, if he goes back he can edit the form.

Since in step 4 the user is at the view `summary` I have to redirect him to the `home` view. I don´t want the user to fill out the entire form again, the previously entered data should be autofilled if he goes back.

Something special: I am using [django-tagify2](https://github.com/gojuukaze/django-tagify2) for one input in the form to get tags rather then text. If the user goes back the tags should be rendered correctly in the tagify specific form.

So here are my files:

home.html

```
{% extends "messenger/base.html" %}
{% load crispy_forms_tags %}
{% block content %}
    <div class="message-container">
    <form method="POST" autocomplete="off">
        {% csrf_token %}
        {{ form|crispy }}
        <button name="sendmessage" class="btn btn-outline-info" type="submit">Continue</button>
    </form>
    </div>
{% endblock content %}

```

summary.html

```
{% extends "messenger/base.html" %}
{% block content %}
    <h4>Zusammenfassung</h4>
    <p><b>Empfänger: </b>{{ receiver }}</p>
    <br>
    <p><b>Betreff: </b>{{ subject }}</p>
    <br>
    <p><b>Nachricht: </b>{{ message }}</p>
    <button><a href="/">Edit</a></button>
    <button><a href="/send_message">Continue</a></button>
{% endblock content %}

```

home view

```
@login_required(login_url='login')
def home(request):
    if request.method == 'POST' and 'sendmessage' in request.POST:
        message_form = MessageForm(request.POST)
        if message_form.is_valid():
            receiver_list = message_form['receiver'].value().split(';')
            subject = message_form['subject'].value()
            message = message_form['textmessage'].value()

            #create sessions and send data to next view
            session_receiver = receiver_list
            request.session['session_receiver'] = session_receiver
            session_subject = subject
            request.session['session_subject'] = session_subject
            session_message = message
            request.session['session_message'] = session_message

            return redirect('summary')

    else:
        message_form = MessageForm()

    return render(request, 'messenger/home.html', {'form': message_form})

```

summary view

```
def summary(request):
    receiver = request.session.get('session_receiver')
    subject = request.session.get('session_subject')
    message = request.session.get('session_message')

    return render(request, 'messenger/summary.html', {'receiver':receiver,
                                                      'subject':subject,
                                                      'message':message})

```

So what is the best way to do this?
Can I use the session variables to set the fields in the form?

I don´t want to change the logic in the app. I want a home/summary/success view/template where I can loop as long is I want between home and summary until the user is happy with his entered form data