Requirements
REST framework requires the following:
- Python (2.7, 3.4, 3.5, 3.6, 3.7)
- Django (1.11, 2.0, 2.1, 2.2)
We highly recommend and only officially support the latest patch release of each Python and Django series.
The following packages are optional:
- coreapi (1.32.0+) - Schema generation support.
- Markdown (2.1.0+) - Markdown support for the browsable API.
- django-filter (1.0.1+) - Filtering support.
- django-crispy-forms - Improved HTML display for filtering.
- django-guardian (1.1.1+) - Object level permissions support.
Installation
Install using pip
, including any optional packages you want...
pip install djangorestframework
pip install markdown # Markdown support for the browsable API.
pip install django-filter # Filtering support
...or clone the project from github.
git clone https://github.com/encode/django-rest-framework
Add 'rest_framework'
to your INSTALLED_APPS
setting.
INSTALLED_APPS = (
...
'rest_framework',
)
If you're intending to use the browsable API you'll probably also want to add REST framework's login and logout views. Add the following to your root urls.py
file.
urlpatterns = [
...
url(r'^api-auth/', include('rest_framework.urls'))
]
drf 文档配置
from rest_framework.documentation import include_docs_urls
urlpatterns = [
url(r'^api-auth/', include('rest_framework.urls')),
# 生产drf自动文档配置
path('docs/',include_docs_urls(title="商品测试")),
]
Note that the URL path can be whatever you want.
网友评论