FastAPI+React 全栈开发

92 阅读1分钟

Setting Environment and dependencies

Need to create the front-end and back-end folder under the main project file respectively. cd to open the backend folder and set as following:

python -m venv env
.\env\Scripts\Activate.ps1    

if you are using MacOS, then replace the last line with source venv/bin/activate. If there are errors in your Powershell, it can probably be solved by opening the administrator of Powershell by set-executionpolicy remotesigned and choose Y if you met error like:

... can't be loaded because running scripts is disabled on this system

If you are using another operating system, please check the relevant information yourself. You may also refer to the offical document for setting Python environment: docs.python.org/zh-cn/3/lib…

Necessary installation

  • Update your pip: python.exe -m pip install --upgrade pip
  • Download packages: pip3 install passlib[bcrypt] SQLAlchemy fastapi[all] pyjwt
    • passlib[bcrypt]: Passlib is a password hash library that provides an easy and secure way to handle passwords. bcrypt is one of these hashing algorithms, which is a secure hash function for encrypting passwords that converts them to an irreversible hash value. It increases the security of the password by adding salt values and multiple iterations.

    • SQLAlchemy: SQLAlchemy is a Python SQL tool and object Relational mapping (ORM) library. It provides a convenient way to interact with the database and can easily perform database operations (such as queries, inserts, updates, deletions, etc.). The ORM section provides a way to map database tables to Python objects, making manipulating the database more intuitive and manageable.

    • fastapi[all]: FastAPI is a modern, fast (high-performance) Web framework for building Python-based apis. fastapi[all] is an installation option for FastAPI that contains the main FastAPI dependencies, as well as other commonly used tools and plug-ins such as database support, authentication, and so on. Installing fastapi[all] reduces the effort of manually installing dependencies.

    • pyjwt: PyJWT is a Python implementation of JSON Web Token (JWT). JWT is an open standard for securely transferring information between network applications (RFC 7519). With JWT, you can generate, validate, and resolve tokens that are used to authenticate users and implement authentication and authorization functions.

Now it's time for us to create files we need.