我在 Flask 中创建了一个联系表单,但它不起作用。它给出了错误 NameError: global name 'ContactForm' is not defined
自定义表格是:
<form action="{{ url_for('contact') }}" method=post>
{{ form.hidden_tag() }}
{{ form.name.label }}
{{ form.name }}
{{ form.email.label }}
{{ form.email }}
{{ form.subject.label }}
{{ form.subject }}
{{ form.message.label }}
{{ form.message }}
{{ form.submit }}
</form>
routes.py 是:
from flask import Flask, render_template
from forms import ContactForm
app = Flask(__name__)
def contact():
form = ContactForm()
if request.method == 'POST':
return 'Form posted.'
elif request.method == 'GET':
return render_template('contact.html', form=form)
if __name__ == '__main__':
app.run(debug=True)
我该如何解决问题?