Flask WTF表格验证错误

时间:2016-12-23 20:22:47

标签: python flask wtforms flask-wtforms

我是Flask的新手,我正在尝试从登录表单中取一个用户输入的名称并将其传递给另一个页面。使用我当前的代码,表单不会在result页面传递任何参数,并在none视图中调用request.args.get('artistName')时返回result。怎么了? print form.errors没有显示任何内容。

views.py计划:

from flask import render_template, request, url_for, redirect

from app import app
from .forms import UserName

@app.route('/', methods=['GET','POST'])
def login():
    form = UserName()

    if form.validate_on_submit():
        return redirect('/result')

    render_template('home.html',form=form)

@app.route('/result', methods=['POST', 'GET'])
def result(name):
    return render_template('results.html')

home.html

{% extends "base.html" %}

{% block content %}
  <form action="{{ url_for('result') }}" method='post'>
    {{ form.csrf_token }}
    {{ form.hidden_tag }}
    <p>Enter your artist name: </p>
    {{ form.artistName(size=100) }}
    {{ form.submit }}
  </form>
{% endblock %}

forms.py

from flask_wtf import FlaskForm
from wtforms import TextField, SubmitField
from wtforms.validators import DataRequired

class UserName(FlaskForm):
    artistName = TextField('artistName', [DataRequired()])
    submit = SubmitField("Go")

我真的很感激任何帮助!

0 个答案:

没有答案