Created
January 17, 2017 22:53
-
-
Save fabiocerqueira/2aea273273b1474aa813cb908a4840ae to your computer and use it in GitHub Desktop.
Using splitted views
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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