i am trying to print a success message after an add operation in my python django project.but the success message is not printing.it prints None.below is my code.what am i doing wrong?
def edit_toners_save(request):
if request.method == "POST":
toner_id = request.POST.get("toner_id")
toner_model = request.POST.get("toner_model")
toner_printer_id = request.POST.get("toner_printer")
toner_printer = Items.objects.get(id=toner_printer_id)
# issued_to_id = request.POST.get("issued_to")
# issued_to = Prosecutions.objects.get(id=issued_to_id)
total_qty = request.POST.get("total_qty")
Toners_model = Toners(id=toner_id, toner_model=toner_model, toner_printer=toner_printer, total_qty=total_qty)
Toners_model.save()
print(messages.success(request, "done"))
calc_total_qty()
print(messages.WARNING)
return redirect('view_toners')
else:
return redirect('view_toners')[![enter image description here][1]][1]
CodePudding user response:
messages.success
doesn't return. you are looking for something like get_messages()
According to the official doc from django in here:
from django.contrib.messages import get_messages
storage = get_messages(request)