1
Fork 0
This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
django-client-reverse/django_client_reverse/views.py

19 lines
667 B
Python
Raw Normal View History

2015-12-09 22:02:27 +00:00
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.renderers import JSONRenderer
2015-12-10 14:25:08 +00:00
from django.core.urlresolvers import reverse, NoReverseMatch
2015-12-10 14:02:38 +00:00
from .serializers import ReverserInputSerializer
2015-12-09 22:02:27 +00:00
class Reverser(APIView):
renderer_classes = (JSONRenderer,)
2015-12-10 14:02:38 +00:00
def post(self, request, format=None):
input_serializer = ReverserInputSerializer(data=request.data)
input_serializer.is_valid(raise_exception=True)
2015-12-10 14:25:08 +00:00
try:
url = reverse(input_serializer.validated_data['ident'])
except NoReverseMatch:
return Response(status=404)
return Response(url, 302)