Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: TemplateDoesNotExist (rest_framework/api.html)

In my view function, I'd like to return a json object (data1) and some text/html (form). Is this possible?

MY code

@api_view(['POST'])
@permission_classes((AllowAny,))
def create_user(request):
    if request.is_ajax():
        if request.method == 'POST':
            serializer = SignupSerializer(data=request.data)
            print 'ser'
            print serializer
            if not serializer.is_valid():
                return Response(serializer.errors,\
                                status=status.HTTP_400_BAD_REQUEST)
            else:
                serializer.save()
                data={'status': 'Created','message': 'Verification email has been sent to your email. Please verify your account.'}
                return Response(data, template_name='register.html')
    else:
        return HttpResponse('hello world')

When I call the url I get status code 500 with error as displayed below

TemplateDoesNotExist rest_framework/api.html

when I check as a API, I get response with 200 ok status. This shows Im unable to get my html page

How should I get my html depending on request

Thanks in advance

like image 791
Coeus Avatar asked Jul 14 '16 06:07

Coeus


2 Answers

Make sure you have rest_framework in your settings's INSTALLED_APPS

like image 196
Linovia Avatar answered Nov 06 '22 06:11

Linovia


Make sure you install pip install djangorestframework and include rest_framework in the setting.py

INSTALLED_APPS = [
    'rest_framework',
]
like image 79
sarath kumar Avatar answered Nov 06 '22 06:11

sarath kumar