[英]SyntaxError: invalid syntax but followed the WTF documentation and still doesn't accept it
Learning python flask and WTF.学习 python flask 和 WTF。 Been working on the code below based of the documentation and tutorials however cannot seem to locate the error.
一直在根据文档和教程处理下面的代码,但似乎无法找到错误。
Controller.py Controller.py
from flask import Flask, escape, request, render_template, url_for, flash, redirect, send_from_directory, json, jsonify
from flask_wtf import FlaskForm
from wtforms import (StringField, PasswordField, SubmitField, BooleanField, DateTimeField,
RadioField, SelectField, TextField, TextAreaField, SubmitField)
from wtforms.validators import DataRequired, Length, Email, EqualTo
from form import infoForm
app = Flask(__name__)
app.config['SECRET_KEY'] = 'asdfghjklqwertyuiop1234567890'
@app.route('/test', methods=['GET','POST'])
def test():
breed = False
form = infoForm()
if form.validate_on_submit():
session['breed'] = form.breed.data
session['neutered'] = form.neutered.data
session['mood'] = form.mood.data
session['food_option'] = form.food_option.data
# breed = form.breed.data
# form.breed.data = ''
# return render_template('test.html', form = form, breed = breed)
return redirect(url_for('/'))
return render_template('test.html', form = form)
forms.py forms.py
class infoForm(FlaskForm):
# Used by forms.py essentially
breed = StringField("What breed are you?", validators = [DataRequired()])
neutered = BooleanField("Have you been neutered?"), choices = ['Yes'])
mood = RadioField('Please choose your mood: '),choices = [('mood_one','Happy'), ('mood_2','Sad')]
food_option = SelectField(u'Pick your fav food: '), choices = [('chic','Chicken') , ('bf','beef') , ('fish','fish')])
submit = SubmitField('Submit')
Response I get on my terminal is:我在终端上得到的响应是:
Traceback (most recent call last):
File "/Users/himanshu/Documents/MasterInt/HMSpython/controller.py", line 21, in <module>
from form import infoForm
File "/Users/himanshu/Documents/MasterInt/HMSpython/form.py", line 22
food_option = SelectField(u'Pick your fav food: ', choices = [('chic','Chicken') , ('bf','beef') , ('fish','fish')])
^
The arrow is under - after the word 'chic',
箭头在 - 在
'chic',
Would like to understand where am I going wrong as I did follow the documentation?想了解我在遵循文档时哪里出错了?
Thank you!谢谢!
You got closing parenthesis ')' in wrong place on radiofields and booleanfield.您在无线电场和布尔场上的右括号“)”位于错误的位置。 You close the parenthesis before choices.
在选择之前关闭括号。 Maybe that's the problem.
也许这就是问题所在。 And put a space after comma, not before.
并在逗号之后放置一个空格,而不是之前。 You can see what i mean down below.
你可以在下面看到我的意思。
class infoForm(FlaskForm):
# Used by forms.py essentially
breed = StringField("What breed are you?", validators=[DataRequired()])
neutered = BooleanField("Have you been neutered?", choices=['Yes'])
mood = RadioField('Please choose your mood:', choices=[('mood_one', 'Happy'), ('mood_2', 'Sad')])
food_option = SelectField(u'Pick your fav food:', choices=[('chic', 'Chicken'), ('bf', 'beef'), ('fish', 'fish')])
submit = SubmitField('Submit')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.