when I want to checking the answers of a random question, flask debugger showing that error list indices must be integers or slices, not str
my Code
from flask import Flask, render_template, flash, request, redirect, url_for
import random
app = Flask(__name__)
data = [{'q':'question text 1', 'ans':'a1', 'idsh':101}, {'q':'question text 2', 'ans':'a2', 'idsh':102}, {'q':'question text 3', 'ans':'a3', 'idsh':103}, {'q':'question text 4', 'ans':'a4', 'idsh':104}, ]
@app.route("/")
def home():
return render_template('index.html', data = random.choice(data))
@app.route('/anss')
def answerd():
if request.args.get('ans') == data['ans']:
return "yes"
else:
return "no"
if __name__ == '__main__':
app.run()
Aucun commentaire:
Enregistrer un commentaire