Q:

Use redirect with locals

I am trying to use django.form redirect to redirect to a page after a process but sending a variable to the page to be rendered.
The code is:
...
if form.is_valid():
            form.save()
            confirmation_message = "Coworker information updated successfully!"
            coworkers = Coworkers.objects.all()
            return redirect('/coworkers/', locals())
...

In my html it should be:
{% extends 'base/base.html' %}

{% block content %}

    <a href="add_coworker">Add Coworker</a>
    <br/><br/>
    {% if confirmation_message %}
        {{ confirmation_message }}
        <br/><br/>
    {% endif %}

    {% for coworker in coworkers %}
        <a href="{{ coworker.id }}">{{ coworker.first_name|capfirst }} {{ coworker.last_name|capfirst }}</a></br>
    {% endfor %}

{% endblock%}

The variable "coworkers" is working because of the other view called by url "/coworkers/". But the variables "confirmation_message" and "coworkers", present in THIS view, is not working.
Can't I use "locals()" when using django redirect?
How could I solve that?
Thanks in advance to all! 

A:

People seem to have a lot of conceptual trouble with redirections: you're not the first to ask a similar question.
When you redirect, you're telling the user's browser to ask for a new URL. That's all. It simply doesn't make sense to ask what you're asking. The only things you can send to a redirect call are parameters that go in the URL.
For anything else, you need to store it somewhere - that's what the session is for. Note that for the specific case of messages, Django has a messages framework that will do all the work for you.
(BTW, I absolutely hate this use of locals() to send a context to a template. Build up a dictionary manually: it's not much typing, and it's much more explicit.)

