Check If Form Input Field is Not Empty Django.How

Author avatar wrote on 06/06/2022

If input fiels is not empty

if request.POST['Name']:
    news.name = request.POST['Name']
else:
    print('No name submitted')

If input filed name in request

if 'customer_id' in request.session:
    customer = Customer.objects.get(id=request.session['customer_id'])

Session and request

If in POST request

if 'amount' in request.POST:
    payment_amount = float(request.POST['amount'])

If in GET request

if 'amount' in request.GET:
    payment_amount = float(request.GET['amount'])

If in session

if 'customer_id' in request.session:
    customer = request.session['customer_id']

If in COOKIES

if 'username' in request.COOKIES and 'last_connection' in request.COOKIES:
      username = request.COOKIES['username']

CRUDgen Django CRUD generator