We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I can create a custom parser when create the NinjaAPI but I can't create a custom parser in routers. How can I do this ?
NinjaAPI
I want to add parser in router like blow.
from ninja import NinjaAPI from ninja.parser import JSONParser, FormParser api = NinjaAPI() @api.post("/json/", parser=JSONParser()) def handle_json(request, data: dict): return {"received_data": data} @api.post("/form/", parser=FormParser()) def handle_form(request, name: str, age: int): return {"name": name, "age": age}
from ninja.parser import Parser from lxml import etree class XMLParser(Parser): def parse_body(self, request): body = request.body.decode() root = etree.fromstring(body) return {child.tag: child.text for child in root} from ninja import NinjaAPI api = NinjaAPI(parser=XMLParser()) @api.post("/xml/") def handle_xml(request, data: dict): return {"received_data": data}
The text was updated successfully, but these errors were encountered:
No branches or pull requests
I can create a custom parser when create the
NinjaAPI
but I can't create a custom parser in routers. How can I do this ?problem
I want to add parser in router like blow.
I CAN DO
I WANT TO DO, BUT I CAN NOT
The text was updated successfully, but these errors were encountered: