from flask import Flask, render_template, request, redirect, session
import random
app = Flask(__name__)
app.secret_key = "guess_secret"
@app.route('/')
def landing_page():
if 'num' not in session:
session['num'] = random.randrange(0,101)
if 'message' not in session:
session['message'] = ''
if 'color' not in session:
session['color'] = ''
return render_template('indexa.html', msg = session['message'], color = session['color'])
@app.route('/execute', methods=['POST'])
def check_guess():
session(['guess']) = int(request.form['guess'])
if (session['guess']==session['num']):
session['message'] = str(session['num'])+'was the number!'
session['color']='green'
elif int(request.form['guess']) < session['num']:
session['message'] = 'Too low.'
session['color']='red'
else:
session['message'] = 'Too high.'
session['color']='red'
return redirect('/')
@app.route('/reset', methods=['POST'])
def reset():
session.pop('number')
session.pop('guess')
session.pop('color')
return redirect('/')
app.run(debug=True)
I'm trying to create a guessing game flask page. keeps coming back "File "guess.py", line 27 session['color']='red' ^ IndentationError: unindent does not match any outer indentation level
Even though the code seems to be syntactically right, it looks as if this part:
was probably meant to be this:
Also be sure not to mix tabs and spaces. If you use spaces for indent, make sure there are no tabs at all in the code.