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)
どうすれば問題を解決できますか?