Enabling cache and images not loading in django? [закрыт]
If you enable the cache:
@cache_page(20, key_prefix='index_page')
def index(request):
post_list = Post.objects.order_by('-pub_date').all()
paginator = Paginator(post_list, 10)
page_number = request.GET.get('page')
page = paginator.get_page(page_number)
return render(request, "index.html", {'page': page, 'paginator': paginator})
When I create a new post, I can no longer upload an image.
@login_required
def post_edit(request, username, post_id):
profile = get_object_or_404(User, username=username)
post = get_object_or_404(Post, pk=post_id, author__username=username)
if request.user != post.author:
return redirect('post', username=username, post_id=post_id)
form = PostForm(request.POST or None, files=request.FILES or None, instance=post)
if form.is_valid():
form.save()
return redirect('post', username=username, post_id=post_id)
return render(request, 'post_new.html', {'form': form, 'post': post})
How can I fix this so that it was possible to download pictures and use the cache?