![]() |
In this article, we will talk about Python-based Flask login without a database in this article. In order to use Flask login without a database in this method basically we are using a python dictionary through which users will be able to log in using their login credentials that we add to the database and also the functionality of logout will be added in this login system in profile page through which user can log out. before that we will understand some important terminology:
Flask Login without DatabaseTemplates FileFirst, we make a templates folder for HTML files, In the templates folder, we are making two HTML files one for login and another for the welcome profile page .so first we make login.html for making the login page login.html We are writing code for the login page in which we first write the welcome login page message, add the details message, fill out the username and password inputs, call the info method to call the flashing error/warning message, and make one action and one method for the login system before connecting this file to the HTML file. If we enter the proper username and password, the login page will transfer us to the user profile page; if we enter the wrong information, the login page will display an invalid username or password warning. To submit this we are adding one submit button. HTML
Output: ![]() Login Page home.html When we successfully log in using the correct username and password, one welcome user (username) message will appear on the display screen in this HTML file, and we are also writing for one logout button utilizing which we can redirect to the login page. When a user clicks one of our buttons, we add the URL for the (‘login’) tag, which calls the login function and directs them to the login page. HTML
Output: ![]() user Profile Page app.pyWe are importing several libraries into the app.py file that are required for the login system. We import the render template to call the HTML file, and after initializing the flask function, we create the hello world function that enables us to call the login.html file. We create a login function in which we make a request in Python and call the username and password from the dictionary, and we create an if and else condition in which we are writing some flashing message that will show the wrong password and wrong username. We use a dictionary to add the username and password details of users for login, and we can add and remove users as well as change the password of any user at any time. Python3
After writing this code we run it in your terminal following the command: flask run Output: |
Reffered: https://www.geeksforgeeks.org
Python |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 18 |