This error happens when DRF attempts to render the browsable API, which
requires it to be in the installed applications. You're probably not seeing
it consistently if not all of your views allow the browsable API to be
rendered.

On Thu, Jan 26, 2017, 16:18 Ryan Mattes <[email protected]> wrote:

> So I have a fairly large Django site and I'm using DRF mostly because it
> provides a convenient way for me to allow multiple authentication methods.
> I don't have all of rest framework installed in my installed apps, only
> rest_framework.authtoken. My views look like this:
>
> @api_view(['POST'])
> @authentication_classes((SessionAuthentication, BasicAuthentication,
> TokenAuthentication))
> @permission_classes((IsAuthenticated,))
> def notifications(request):
>
>     ret = {
>         'action': 'Message Sent',
>         'users': [],
>         'stack': []
>     }
>     try:
>         data = request.data
>     except:
>         return HttpResponse(JsonResponse({"error": "Invalid request",
> "data": request}))
>
>     ...
>
>
>     return HttpResponse(JsonResponse(ret))
>
> @api_view(['POST'])
> @authentication_classes((SessionAuthentication, BasicAuthentication,
> TokenAuthentication))
> @permission_classes((IsAuthenticated,))
> @login_required
> def addtogroup(request):
>     ret = {
>         "action": "Add to group",
>         "group": None,
>         "users": []
>     }
>     data = {}
>     try:
>         data = request.data
>     except:
>         return HttpResponse(JsonResponse({"error": "Invalid request",
> "data": request}))
>
>
>     ...
>
>
>     return HttpResponse(JsonResponse(ret))
>
>
>
> For most of the views I treated like this it work just fine, but for some
> reason, some of the time, I get:
>
> Exception Type: TemplateDoesNotExist
> Exception Value: rest_framework/api.html
>
> Why does this work sometimes but not others?
>
> I realize that this is probably not how DRF was intended to be used, but
> it seems like it should either work or not, and not break only on certain
> urls/views.
>
> Anyone have any idea why this is happening?
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django REST framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to