import json
from django.shortcuts import render
from django.http import HttpResponse, JsonResponse
from reportlab.pdfgen import canvas

def Index(request):
    return render(request, "ReturnType/index.html")

def JSON(request):
    data = {
        'name': 'C.K.Leng',
        'gender': 'male',
        'age': 18,
        'married': False
    }
    return JsonResponse(data)
    #return HttpResponse(json.dumps(data), content_type='application/json')

def PDF(request):
    response = HttpResponse(content_type='application/pdf')
    response['Content-Disposition'] = 'attachment; filename="file.pdf"'
    p = canvas.Canvas(response)
    p.setFont("Times-Roman", 55)
    p.drawString(100, 700, "Hello, Students")
    p.showPage()
    p.save()
    return response

def SVG(request):
    file = open('./static/images/my.svg', 'rb')
    response = HttpResponse(content=file)
    response['Content-Type'] = 'image/svg+xml'
    return response

def JPG(request):
    file = open('./static/images/Logo.jpg', 'rb')
    response = HttpResponse(content=file)
    response['Content-Type'] = 'image/jpeg'
    return response