django - Success variable message is assigned referenced before assignment -
i'm trying show success message after posting data on form.
def addcostumer(request): form = costumerform(request.post or none) if form.is_valid(): save_it = form.save(commit=false) save_it.save() message = "data sent!" return render_to_response('nuevocliente.html', {'message': message}, context_instance=requestcontext(request),)
you need check if request indeed post
, show message if form
submitted indeed valid.
also, looks forgot send actual form in context.
def addcostumer(request): form = costumerform() message = none #set message none 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 object saved successfully. return render_to_response('nuevocliente.html', {'message': message, 'form': form}, context_instance=requestcontext(request))
Comments
Post a Comment