Skip to content
New issue

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

Decorator to show fields for api views #161

Open
realsby opened this issue Mar 12, 2017 · 0 comments
Open

Decorator to show fields for api views #161

realsby opened this issue Mar 12, 2017 · 0 comments

Comments

@realsby
Copy link

realsby commented Mar 12, 2017

I have a api view. I want to show fields in docs. Do we need a decorator to show fields in docs?

@api_view(['POST'])
@permission_classes((AllowAny, ))
@throttle_classes([AnonRateThrottle])
@api.doc(fields={'email': 'CharField', 'password':'CharField'})
def change_password(request):
    signed_email = request.data.get('email', '')
    password = request.data.get('password', '')

    try:
        email = loads(urlunquote(signed_email))
    except BadSignature:
        return Response(status=status.HTTP_400_BAD_REQUEST)

    if len(password) < 6:
        return Response(status=status.HTTP_400_BAD_REQUEST)

    if not User.objects.filter(username=email):
        return Response(status=status.HTTP_404_NOT_FOUND)

    user = User.objects.get(username=email)
    user.set_password(password)
    user.save()

    return Response(status=status.HTTP_200_OK)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant