10 – HOW TO CLEAR A FORM IN DJANGO AFTER SAVING – INVOICE MANAGEMENT SYSTEM

Spread the love

In chapter 08 of this series, we covered how to input data through the front end of the application. In this chapter, I will show you how to empty the form data after clicking the save button.

  1. Import render redirect to allow you the page to be redirected to another after saving the data.
from django.shortcuts import render, redirect

Add return redirect immediately after form.save()

2. Now to empty the form, we will reload the page to give us a new and empty form, thus clearing the form and getting it ready to input a new record.

We will add this if condition to the entry view in views.py

if form.is_valid():
    form.save()
    return redirect('/add_invoice')

Spread the love

About the author

arbadjie

Hi, I'm Abdourahman Badjie, an aspiring developer with obsession for anything coding and networking. This blog is dedicated to helping people learn to develop web applications using django framework.

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *