FastAPI Tutorial
Selected Reading
- FastAPI - Discussion
- FastAPI - Useful Resources
- FastAPI - Quick Guide
- FastAPI - Deployment
- FastAPI - Mounting Flast App
- FastAPI - Middleware
- FastAPI - Mounting A Sub-App
- FastAPI - FastAPI Event Handlers
- FastAPI - Websockets
- FastAPI - Using GraphQL
- FastAPI - Using MongoDB
- FastAPI - SQL Databases
- FastAPI - Crud Operations
- FastAPI - CORS
- FastAPI - Dependencies
- FastAPI - Nested Models
- FastAPI - Response Model
- FastAPI - Header Parameters
- FastAPI - Cookie Parameters
- FastAPI - Uploading Files
- FastAPI - Accessing Form Data
- FastAPI - HTML Form Templates
- FastAPI - Static Files
- FastAPI - Templates
- FastAPI - Request Body
- FastAPI - Pydantic
- FastAPI - Parameter Validation
- FastAPI - Query Parameters
- FastAPI - Path Parameters
- FastAPI - Rest Architecture
- FastAPI - IDE Support
- FastAPI - Type Hints
- FastAPI - Uvicorn
- FastAPI - OpenAPI
- FastAPI - Hello World
- FastAPI - Introduction
- FastAPI - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
FastAPI - HTML Form Templates
FastAPI - HTML Form Templates
Let us add another route "/login" to our apppcation which renders a html template having a simple login form. The HTML code for login page is as follows −
<html> <body> <form action="/submit" method="POST"> <h3>Enter User name</h3> <p><input type= text name= nm /></p> <h3>Enter Password</h3> <p><input type= password name= pwd /></p> <p><input type= submit value= Login /></p> </form> </body> </html>
Note that the action parameter is set to "/submit" route and action set to POST. This will be significant for further discussion.
Add login() function in the main.py file as under −
@app.get("/login/", response_class=HTMLResponse) async def login(request: Request): return templates.TemplateResponse("login.html", {"request": request})
The URL http://localhost:8000/login will render the login form as follows −
Advertisements