Skip to main content
===============
drf-api-actions
===============

提供django下rest framework的coreapi便捷调用

Quick start for django 2.0+
-----------
1. Install::

pip install drf_api_actions>=2.0


2. [Optional] Include the drf_api_actions URLconf in your project urls.py like this::

if settings.DEBUG:
urlpatterns += [
url('^', include('drf_api_actions.urls'))
]

# after add this you can visit: /docs /schema /api.js

3. No migrate needed:

4. Sample::

# Add "sample" to your INSTALLED_APPS setting like this ::
INSTALLED_APPS = [
...
'sample',
]

# Include the sample URLconf in your project urls.py like this::
urlpatterns += [
url('^', include('sample.urls'))
]

# Run server and visit /docs /schema /api.js

5. Examples::

# Views
class UsersAPIView(APIView):
"""
获得用户列表

返回值:用户列表 `['a', 'b', ...]`

"""

def get(self, request):
return Response(['a', 'b'])


class UsersActionReadAPIView(ActionReadMixin, APIView):
"""
获得用户列表, 用了`ActionReadMixin`后这是一个用 Read

返回值:用户列表 `['a', 'b', ...]`

"""

def get(self, request):
return Response(['a', 'b'])


class UsersExtraFieldsAPIView(APIView):
"""
获得用户列表, 带user_id/user_name会过滤

返回值:
- 带user_id: `['a']`
- 不带user_id: `['a','b']`
"""

schema = AutoSchema(manual_fields=[
coreapi.Field(name='user_id', location='query', required=True,
schema=coreschema.String(description='用户的id')),
])

def get(self, request):
user_id = request.GET.get('user_id', '')
if user_id:
return Response(['a'])
else:
return Response(['a', 'b'])

# Url settings
url('^docs/', Views.docs_as_view(title='API'))
url('^schema/', Views.schema_as_view(title='API'))
url('^api.js', Views.api_js_as_view(title='API'))



Quick start for django 1.0+
-----------
1. Install::

pip install drf_api_actions==0.2.0


2. [Optional] Include the drf_api_actions URLconf in your project urls.py like this::

if settings.DEBUG:
urlpatterns += [
url('^', include('drf_api_actions.urls'))
]

# after add this you can visit: /docs /schema /api.js

3. No migrate needed:

4. Sample::

# Add "sample" to your INSTALLED_APPS setting like this ::
INSTALLED_APPS = [
...
'sample',
]

# Include the sample URLconf in your project urls.py like this::
urlpatterns += [
url('^', include('sample.urls'))
]

# Run server and visit /docs /schema /api.js

5. Examples::

# Views
class UsersAPIView(APIView):
"""
获得用户列表

返回值:用户列表 `['a', 'b', ...]`

"""

def get(self, request):
return Response(['a', 'b'])


class UsersActionReadAPIView(ActionReadMixin, APIView):
"""
获得用户列表, 用了`ActionReadMixin`后这是一个用 Read

返回值:用户列表 `['a', 'b', ...]`

"""

def get(self, request):
return Response(['a', 'b'])


class UsersExtraFieldsAPIView(APIView):
"""
获得用户列表, 带user_id/user_name会过滤

返回值:
- 带user_id: `['a']`
- 不带user_id: `['a','b']`
"""

extra_fields = [
coreapi.Field(name='user_id', location='query', required=False,
schema=coreschema.String(description='用户id'))
]

def get(self, request):
user_id = request.GET.get('user_id', '')
if user_id:
return Response(['a'])
else:
return Response(['a', 'b'])

# Url settings
url('^docs/', Views.docs_as_view(title='API'))
url('^schema/', Views.schema_as_view(title='API'))
url('^api.js', Views.api_js_as_view(title='API'))

Metadata

Release files for drf-api-actions 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for drf-api-actions 2.0.0
File Size Uploaded Provenance Actions
drf-api-actions-2.0.0.tar.gz 7.8 kB Without provenance Details for drf-api-actions-2.0.0.tar.gz

Release files / drf-api-actions-2.0.0.tar.gz

Download URL drf-api-actions-2.0.0.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
1087a4f310534f473a05d35391e175f2a80abc66aa1f856fcf1c129590da7c63
BLAKE2b-256 checksum
How to use checksums
1512fe4d334d608106aec1c1540293699c0bfbcc077bebcb68995cc18fda3c41
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for drf-api-actions 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page