The first file will be the _init_.py file for the project: Let’s start by creating a project directory:
Now that you have installed the packages, you are ready to create the main app file.
Codigo html para intro flash install#
pip install flask flask-sqlalchemy flask-login.Run the following command from your virtual environment to install the needed packages: This command will activate the virtual environment. This will create a new directory containing bin, include, and lib subdirectories.
This command will execute the module venv to create a new virtual environment named auth. Note: You can consult the tutorial relevant to your local environment for setting up venv.ĭepending on how Python was installed on your machine, your command will look similar to: You will want to create a Python environment if you don’t have one. You will be using SQLite to avoid having to install any extra dependencies for the database.įirst, start with creating the project directory: Flask-SQLAlchemy: to represent the user model and interface with the database.Flask-Login: to handle the user sessions after authentication.There are three main packages you need for your project: This tutorial was verified with sqlite3 v3.36.0, python v3.9.8, flask v2.0.2, flask-login v0.5.0, and flask-sqlachemy v2.5.1. ├── base.html # contains common layout and linksĪs you progress through the tutorial, you will create these directories and files. ├── main.py # the non-auth routes for the app ├── auth.py # the auth routes for the app Here is a diagram to provide a sense of what the file structure of the project will look like once you have completed the tutorial. Knowledge of Basic Linux Navigation and File Management.Python installed on a local environment.To complete this tutorial, you will need the following:
Codigo html para intro flash code#
The source code for this project is available on GitHub. Furthermore, modifying the data type for the primary key or considerations for migrating to different database systems are also outside of the scope of this introductory tutorial. Note: This tutorial is limited in scope and does not cover advanced persisting of sessions. You will use information from the User model and display it on the protected pages when the user logs in to simulate what a profile would look like. You will build a sign-up and a login page that allow users to log in and access protected pages. Use information from the user’s account to display on the profile page.Flash error messages back to users when something goes wrong.Create sign-up and login forms for the users to create accounts and log in.Use Flask-SQLAlchemy to create a User model.Add protected pages to the app for logged in users only.Use the built-in Flask utility for hashing passwords.Use the Flask-Login library for session management.You can add authentication to your Flask app with the Flask-Login package. Allowing users to log in to your app is one of the most common features you will add to your web applications.