Home > Back-end >  Python module installation problem with Flask-WTF
Python module installation problem with Flask-WTF

Time:06-24

(Merge this question, if necessary)

I am building a basic Flask-based app within a virtual environment and activated the virtual env. Installed each module correctly including this one. In the process, I have made a primary Py file alongside a file to direct all routes and another one for form. I properly installed the module within the environment and even updated it multiple times.

Whenever I am trying to run it (via Git Bash), it is throwing some scripting error and shows the unavailability of the module Flask-wtf. I could not gather any idea. The error is being occurred for all Py files Inserting only the necessary codes of each Py file:

Main application file*

from flask import Flask
app = Flask(__name__)
app.config['SECRET_KEY'] = 'aaa - key' #key to generate CSRF token
from route import *
if __name__ == '__main__':
    app.run (debug=True)

Route file:

from app import app
from flask import render_template

import forms

@app.route('/')
@app.route('/page1')
def page1():
    return render_template ('page1.html',
    current_title='Head 1')

@app.route('/page2', methods=['GET', 'POST'])
def page2():
    form = forms.AddTaskForm()
    if form.validate_on_submit():
        print('Submitted',form.title.data)
        return render_template('page2.html', form=form, title=form.title.data)
    return render_template ('page2.html', form=form)
  1. Forms

    from wsgiref.validate import validator from flask_wtf import Form, FlaskForm from wtforms import StringField, SubmitField from wtforms.validators import DataRequired

    class AddTaskForm(FlaskForm): title = StringField('Title', validators=[DataRequired()]) submit = SubmitField('Send')

Error:

   app.py", line 6, in <module>
   route.py", line 7, in <module>
    forms.py", line 2, in <module>

    from flask_wtf import FlaskForm
ModuleNotFoundError: No module named 'flask_wtf'

CodePudding user response:

instead try with:

from wtforms import Form, StringField, SubmitField
from wtforms.validators import DataRequired
class AddTaskForm(Form): 
    title = StringField('Title', validators=[DataRequired()]) 
    submit = SubmitField('Send')

CodePudding user response:

install the module

pip install flask-wtf
  • Related