-1
def register(request):
  """Register a new user."""
  if request.method != 'POST':
    # Display blank registration form.
    form = UserCreationForm()
  else:
    # Process completed form.
    form = UserCreationForm(data=request.POST)
    if form.is_valid():
      new_user = form.save()
      # Log the user in and then redirect to home page.
      authenticated_user = authenticate(username=new_user.username,password=request.POST['password1'])
      login(request, authenticated_user)
      return HttpResponseRedirect(reverse('learning_logs:index'))
  context = {'form': form}
  return render(request, 'users/register.html', context)

I got an error: TabError: inconsistent use of tabs and space in indentation I got the ^ just below the ['password1'])

Ricky Nelson
  • 197
  • 1
  • 1
  • 7
  • 1
    Sounds like you are using tabs and spaces. Pick one. – Andy Feb 05 '16 at 05:38
  • 1
    You are (of course) free to pick whatever you want. However, _most_ of the python community follows the guidelines in PEP8 which recommends __4 spaces__. – mgilson Feb 05 '16 at 05:48
  • 1
    I will rather setup a editor accordingly to do what PEP8 requires once for all python code – dlmeetei Feb 05 '16 at 06:06

1 Answers1

0

The existing answer and comments are correct, but here's some more detail:

In your text editor, put your cursor at the beginning of authenticated_user = ..., then click the left arrow button to move the cursor left. You'll find two spaces, then the cursor will jump over a tab which is still present in the code here in your question. That tab needs to be replaced with spaces, or you need to convert all the rest of your code to use tabs (but spaces are preferred, as previously mentioned).

skrrgwasme
  • 9,358
  • 11
  • 54
  • 84
  • Thanks for all replies. Yes, I tried to put my cursor at the beginning and moved to the left found out the there was a tab in front. Now used space bar instead and all good. – Ricky Nelson Feb 09 '16 at 05:35