Tuesday, 13 August 2013

Django error: invalid syntax (, line 1)

Django error: invalid syntax (, line 1)

def play(request):
if request.user.is_authenticated():
number_of_records = Puzzles.objects.count()
random_index = int(random.random()*number_of_records)+1
rand_puzz = Puzzles.objects.get(id = random_index).puzzle
solution = eval(rand_puzz)
if 'a' in request.GET:
a = request.GET['a']
if a == request.GET['solution']:
message = "correct"
return render(request, 'play.html',

{'rand_puzz':rand_puzz,'solution':solution,'message':message})
else:
message = "incorrect"
return render(request, 'play.html',
{'rand_puzz':rand_puzz,'solution':solution,'message':message})
else:
message = 'play the game'
return render(request, 'play.html',
{'rand_puzz':rand_puzz,'solution':solution,'message':message})
else:
return render_to_response('home.html')
So I'm getting this error:invalid syntax (, line 1). The page works
initially, then this will happen. I'm completely baffled by what this
error means and any help would be appreciated

No comments:

Post a Comment