Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im trying to fill a website to login and put my users in my database but i dont know
how to use method post in html.

What I have tried:

from fastapi import FastAPI, status, HTTPException
from pydantic import BaseModel
from typing import Optional, List
from database import SessionLocal
import models

class User(BaseModel):
    id:int
    name:str
    email:str
    password:str

    class Config:
        orm_mode = True

db=SessionLocal()
app=FastAPI()


@app.get("/hello")

async def hi():

    return {"hello my dear"}

@app.post("/create_user",response_model=User)
async def create_user(request:User):
    opj = models.User(
        id=request.id,
        name=request.name,
        email=request.email,
        password=request.password,
    )
    db.add(opj)
    db.commit()
    return opj
Posted
Updated 4-Jul-22 9:11am

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900