-4

When I try to self check if p_username key is available in cleaned_data, using following code:

def clean(self):
    username = self.cleaned_data['p_username']
    if User.objects.filter(username=username).exists():
        raise forms.ValidationError('Username already exists.')
    return username

This code is returning me.

def clean(self):
                   ^
IndentationError: unindent does not match any outer indentation level
nas
  • 2,289
  • 5
  • 32
  • 67

1 Answers1

2

You should read about PEP 0008 before writing a code I guess. It says -

Use 4 spaces per indentation level.

Also there are already some points about this here

def clean(self):
    username = self.cleaned_data['p_username']
    if User.objects.filter(username=username).exists():
        raise forms.ValidationError('Username already exists.')
    return username
Community
  • 1
  • 1
wolendranh
  • 4,202
  • 1
  • 28
  • 37