Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask-Login documentation: LoginForm()

Following the Flask Login manual, I am looking for the right library to include so that I can call the LoginForm() function.

Which library do I need to include that contains the LoginForm() part?

like image 347
Happysmithers Avatar asked Sep 07 '17 08:09

Happysmithers


People also ask

How can I tell if a user is logged into a Flask?

At the same time, you can use Flask-login API to do some configurations in case that you want to use its functionality. When you want to check whether the user has logged in manually rather than use the Flask-login API, then check the value of session['logged_in'] .

How do I add authentication in Flask API?

client() method to make a request to our API to create a user and log in with the same user to obtain the authentication token. Once we have the token, we can now use it to make requests in our tests. Note: To ensure that data is not corrupted, we always drop the test DB and add a new user with every test run.

How do you show logged in user information in Python?

To display a value you need to pass it to render_template("foo. html", username=username) as a kwarg. Try looking into Flask-Login where you can access the logged in user's attributes via current_user i.e {{ current_user. username }} .


1 Answers

LoginForm is a class inherit from FlaskForm
First, you need install some modules: pip install flask flask-login flask-wtf
There is a module (such as form.py) with content:

from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField


class LoginForm(FlaskForm):
    username = StringField('Username')
    password = PasswordField('Password')
    submit = SubmitField('Submit')

This module contains form which be generated by flask_wtf module. And import LoginForm in your script.

from form import LoginForm

File login.html (in templates directory in current directory) will using flask-wtf to generate html code for LoginForm by using wtf.quick_form(form)
You can read example in this article to understand more detail or flask home page to understand structure of flask app

like image 98
tuannv.256 Avatar answered Oct 02 '22 02:10

tuannv.256