Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This error occurred several times before using the if else statement
I tried to remove the colons but the error still exists

from django.shortcuts import render
# create your views.


def Register(request):

	if request.method == 'POST':

else:
     return render(request,"Register.html") 


What I have tried:

<pre>This error occurred several times before using the if else statement
I tried to remove the colons but the error still exists
Posted
Updated 30-Jan-23 17:45pm

1 solution

Indentation is important in Python. It should be:
Python
from django.shortcuts import render
# create your views.

def Register(request):
	if request.method == 'POST':
    else:
        return render(request,"Register.html")

Removing all the redundant blank lines makes it clearer. But a better option would be to change the if test, and remove the else.
Python
from django.shortcuts import render
# create your views.

def Register(request):
	if request.method != 'POST':
        return render(request,"Register.html")
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900