Sunday, 18 August 2013

Django Expected indent block error

Django Expected indent block error

I am starting to learn django. I tried small authentication code and have
got the following error:
expected an indented block (views.py, line 25)
I have everything indented with spaces(5 spaces per indent). My code:
from django.shortcuts import render_to_response , get_object_or_404, render
from django.template import Context, RequestContext,loader
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from models import Auth
from forms import LoginForm
authenticated = 0
def index(request):
global authenticated
form = LoginForm(request.POST)
if request.method == 'POST' and form.is_valid():
details = Auth.objects.create(
username = form.cleaned_data['username'],
passwd = form.cleaned_data['password'],
)
dbdet = Auth.objects.get(pk = 1)
if dbdet.username == details.username and dbdet.passwd ==
details.passwd:
authenticated = 1
return HttpResponseRedirect('welcome/')
else:
return HttpResponse("Sorry! Wrong call")
else:
authenticated = 0
context = RequestContext(request)
return render_to_response('login_page.html',{ 'form': form}, context)
def welcome(request):
t=loader.get_template('welcome.html')
c= RequestContext(request)
return HttpResponse(t.render(c))
def if_authenticated():
return authenticated
# Create your views here.
The error corresponds to the else statement after the pass statement. I do
not know what's wrong with the code. pass statement removed. But then the
error points to the next line( after the else)

No comments:

Post a Comment