Skip to content

Instantly share code, notes, and snippets.

@Spazzy757
Last active May 19, 2018 10:15
Show Gist options
  • Save Spazzy757/1b81ec7778fea51a2e95c7b06b291765 to your computer and use it in GitHub Desktop.
Save Spazzy757/1b81ec7778fea51a2e95c7b06b291765 to your computer and use it in GitHub Desktop.
These are views that will open different types of files in new tabs
# For displaying images in new tab:
def home(request):
image_data = open(“/path/to/my/image.png”, “rb”).read()
return HttpResponse(image_data, mimetype=”image/png”)
# For displaying pdf files in new tab:
def home(request):
image_data = open(“/path/to/my/image.pdf”, “rb”).read()
return HttpResponse(image_data, mimetype=”application/pdf”)
# For displaying videos in new tab:
def home(request):
image_data = open(“/path/to/my/image.mp4”, “rb”).read()
return HttpResponse(image_data, mimetype=”video/mp4″)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment