第一次使用flask-wtf的RecaptchaField,定义如下
配置文件设置
1 # WTF 设置 2 WTF_I18N_ENABLED = False 3 SECRET_KEY = os.getenv('SECRET_KEY', 'some secret words') or 'my secert key dfdfdfdfdfdf' 4 RECAPTCHA_PRIVATE_KRY = os.getenv('RECAPTCHA_PRIVATE_KRY', 'some recapcha private key words') or 'my secert key dghghghghgh' 5 RECAPTCHA_PUBLIC_KRY = os.getenv('RECAPTCHA_PUBLIC_KRY', 'some recapcha public key words') or 'mertefghdfgsdsasdfasdfghjg'
Form表单定义
1 class RegistForm(MyBaseForm): 2 userName = StringField(label='用户名:', validators=[DataRequired(message='必须填写用户名'), Length(min=2, max=20)]) 3 email = StringField(label='邮箱:', validators=[DataRequired(message='必须提供注册邮箱'), Email(message='所提供邮箱需满足邮箱格式')]) 4 password = PasswordField(label='密码:', validators=[DataRequired(message='必须提供登录密码'), Length(min=4, max=20, message='密码长度必须在2-20个字符之间')]) 5 confirm = PasswordField(label='重复密码:', validators=[DataRequired(message='请重复输入密码'), EqualTo('password', message='重复输入密码需与前密码一致')]) 6 recaptcha = RecaptchaField() 7 8 submit = SubmitField(label='注册')
确定在运行中current_app中可以查到config中的['RECAPTCHA_PUBLIC_KRY']
但在运行中报如下错误
跟踪在widgets.py中报这个错误
def __call__(self, field, error=None, **kwargs): """Returns the recaptcha input HTML.""" try: public_key = current_app.config["RECAPTCHA_PUBLIC_KEY"] except KeyError: raise RuntimeError("RECAPTCHA_PUBLIC_KEY config not set") from None return self.recaptcha_html(public_key)
调试跟踪确定有值
请问有大神可以解决吗?
标签:set,key,flask,RECAPTCHA,label,KEY,message,PUBLIC From: https://www.cnblogs.com/hujunf/p/16963472.html