问题
Why do you need to use Django REST framework to make an API? Can't you just create routes like /api/createuser
with normal Django and handle all of the backend logic from there as you would normally?
回答1:
You do not NEED to use Django REST framework to make an API
But if you are going to make a decent REST API in Django, DRF is a framework on top of Django that helps you building an API with following features:
- Web browseable API, documentation autogeneration
- Generic views auto building from models
- Routers
- Body parsers (auto content-negotiation)
- Validators
- Authentication
- Permissions
- Throttling
- Data auto filtering via get params
- 4 different pagination modes (number/offset/time)
- API Versioning
- Multiple response formats (.xml/.json/etc)
- Exception format to current response format
You are free to reinvent the wheel and/or create a buggy/insecure REST API or you can choose to use a well thought and tested framework to help you build a good REST API.
来源:https://stackoverflow.com/questions/42617913/why-do-you-need-to-use-django-rest-api