I assume you’re using PIL (Python Imaging Library). You need to replace your last line with (for example, if you want to serve a PNG image):
response = HttpResponse(mimetype="image/png")
img.save(response, "PNG")
return response
See here for more information.
More Related Contents:
- Django CSRF check failing with an Ajax POST request
- How do I integrate Ajax with Django applications?
- Where’s my JSON data in my incoming Django request?
- Any way to make {% extends ‘…’ %} conditional? – Django
- Add Text on Image using PIL
- Rendering JSON objects using a Django template after an Ajax call
- Why does Tkinter image not show up if created in a function?
- Having Django serve downloadable files
- Django URLs TypeError: view must be a callable or a list/tuple in the case of include()
- Error on “pip install -U channels” command using for otree (Running setup.py bdist_wheel for twisted … error)
- Pygame image transparency confusion [duplicate]
- How to execute a GROUP BY … COUNT or SUM in Django ORM?
- How do I add a placeholder on a CharField in Django?
- How can I programmatically change the background in Mac OS X?
- How to get value from form field in django framework?
- Count number of records by date in Django
- Running Scrapy spiders in a Celery task
- Django migration with uuid field generates duplicated values
- How to set and get session variable in django?
- Race conditions in django
- Django – TypeError – save() got an unexpected keyword argument ‘force_insert’
- Django 404 error-page not found
- python imshow, set certain value to defined color
- django order_by query set, ascending and descending
- How does Django handle multiple requests?
- Automatically cropping an image with python/PIL
- Install mod_wsgi on Ubuntu with Python 3.6, Apache 2.4, and Django 1.11
- Square detection in image
- Multiple figures in a single window
- How to implement a “back” link on Django Templates?