March 2020
Intermediate to advanced
608 pages
17h 17m
English
Execute these steps one by one:
# myproject/apps/ideas/views.pyimport osfrom django.contrib.auth.decorators import login_requiredfrom django.http import FileResponse, HttpResponseNotFoundfrom django.shortcuts import get_object_or_404from django.utils.text import slugifyfrom .models import Idea@login_requireddef download_idea_picture(request, pk): idea = get_object_or_404(Idea, pk=pk) if idea.picture: filename, extension = os.path.splitext(idea.picture.file.name) extension = extension[1:] # remove the dot response = FileResponse( idea.picture.file, content_type=f"image/{extension}" ) slug = slugify(idea.title)[:100] response["Content-Disposition"] ...
Read now
Unlock full access