Skip to content

Instantly share code, notes, and snippets.

@fabiocerqueira
Created January 17, 2017 22:53
Show Gist options
  • Select an option

  • Save fabiocerqueira/2aea273273b1474aa813cb908a4840ae to your computer and use it in GitHub Desktop.

Select an option

Save fabiocerqueira/2aea273273b1474aa813cb908a4840ae to your computer and use it in GitHub Desktop.
Using splitted views
from django.template import engines
from django.http import HttpResponse
from PIL import Image
def image_view(request):
image = Image.new("RGB", (200, 200))
response = HttpResponse(content_type="image/png")
image.save(response, "PNG")
return response
def example(request):
template_code = """
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My Image</title>
</head>
<body>
<img src="{% url 'image_draw' %}">
</body>
</html>
"""
template = engines['django'].from_string(template_code)
return HttpResponse(template.render())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment