[Answer]-Success variable message is assigned referenced before assignment

1👍

You need to check if the request was indeed a POST and then show the message if form submitted is indeed valid.

Also, it looks like you forgot to send the actual form in the context.

def addcostumer(request):
    form = CostumerForm()
    message = None #Set the message to None by default

    if request.method == 'POST':
        form = CustomerForm(request.POST)
        if form.is_valid():
            save_it = form.save(commit=False) 
            save_it.save()
            message = "Data sent!" #Set message if the object was saved successfully.

    return render_to_response('nuevocliente.html', {'message': message, 'form': form}, context_instance=RequestContext(request))

Leave a comment