Django-Tastypie expansion plug-in recommendation and usage method
Django-Tastypie is a powerful framework for building a RESTFUL API. It is closely integrated with the Django framework, enabling developers to easily create and manage APIs.It provides many functions and extension plug -ins, which can further enhance and customize the functions of API.Next, we will introduce some commonly used Django-Tastypie extended plug-in and how they use.
First, we need to install Django-Tastypie.You can use the following command to install through the PIP:
shell
pip install django-tastypie
After the installation is completed, add 'TASTYPIE' to the Installed_apps list in the settings.py file of the project.
Next, we will introduce some common Django-Tastypie extended plug-in and how to use:
1. Tastypie-Swagger:
Tastypie-Swagger is a plug-in to automatically generate API documents.It provides a visual interface that enables developers to easily view the details of the API.To install Tastypie-Swagger, you can use the following commands:
shell
pip install django-tastypie-swagger
After the installation is completed, add 'TASTYPIE_SWAGGER' to the Installed_apps list in the settings.py file of the project.Then, add the following code to the urls.py file of the project:
python
from tastypie_swagger.urls import get_swagger_view
schema_view = get_swagger_view(title='API Documentation')
urlpatterns = [
...
url(r'^swagger/$', schema_view),
...
]
After running the project, you can access the "http:// localhost: 8000/swagger/" in the browser to view the API document.
2. Django-tastypie-Mongoengine:
Django-Tastypie-Mongongine is a plug-in integrated Mongongine in Django-Tastypie.It enables developers to use MongoDB as a database to store and retrieve data.To install Django-Tastypie-Mongongine, you can use the following commands:
shell
pip install django-tastypie-mongoengine
After the installation is complete, add 'TASTYPIE_MONGOENGINE' to the InstalLLED_APPS list in the settings.py file of the project.
3. Tastypie-MongoDB:
Tastypie-Mongodb is a plug-in for mongoDB in Django-Tastypie.It provides integration with the MongoDB database and allows developers to use MongoDB to store and retrieve data.To install Tastypie-Mongodb, you can use the following commands:
shell
pip install django-tastypie-mongodb
After the installation is completed, add 'TASTYPIE_MONGODB' to the Installed_apps list in the project's settypie_mongodb '.
The above is the introduction of some commonly used Django-Tastypie extension plug-ins.When using these plug -ins, it is necessary to perform appropriate allocation according to specific needs, such as defining the resources, fields, filters, etc. of API.You can refer to the official documentation of Django-Tastypie to obtain more detailed configuration and use information.