Skip to content

Getting form details through angular frontend #1706

@AshishGusain17

Description

@AshishGusain17

My angular side code is:

<form aria-labelledby="title"  ngNoForm  [action]="url" method="POST">
        <input type="text" name="email" value="" nbInput fullWidth placeholder="Email Address" >
        <input type="text" name="password" value="" nbInput fullWidth placeholder="Password" >
        <button nbButton fullWidth status="primary" class="mbt" (click)="login()">Login</button >
</form>

The url will be directed to "http://127.0.0.1:8000/getLogin"

Now, I want to fetch details in the fastapi route, but I am unable to fetch. Can anyone answer?
I tried below code:

from fastapi import FastAPI
app = FastAPI()

class userForm(BaseModel):
    email: str = Form(...)
    password: str = Form(...)

@app.post('/getLogin' )
def getLogin(request: Request,userForm: userForm ):
    email = userForm.email
    password = userForm.password
    print(email,password)
    return json.dumps({"reaction":12})

You can see I am getting password and email below but how to get that in my code.
Screenshot (432)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions