Skip to content

Form data

Django Ninja also allows you to parse and validate request.POST data (aka application x-www-form-urlencoded or multipart/form-data).

Here's a quick example:

from ninja import NinjaAPI, Form"/login")
def login(request, username: str = Form(...), password: str = Form(...)):
    return {'username': username, 'password': '*****'}

Note the following:

1) You need to import the Form class from ninja

from ninja import Form

2) Use Form as default value for your parameter:

username: str = Form(...)