我开发了一个pet-ptoject,有点简单的图像共享服务并遇到了这样的困难。我拥有什么以及想要获得什么。
这是来自views.py
的视图def index(request):
# Main page view
form = ImageForm(request.POST or None, request.FILES or None)
images_recent = Image.objects.order_by('-upl_date')[:IMAGE_COUNT]
images_popular = Image.objects.order_by('-rev_count')[:IMAGE_COUNT]
images_like = Image.objects.order_by('-like_count')[:IMAGE_COUNT]
if form.is_valid():
image = form.save(commit=False)
image.user = request.user
image.img = request.FILES['img']
image.desc = request.POST.get('desc')
image.slug = slug_gen()
image.save()
messages.add_message(request, messages.SUCCESS, _('Yee haw! Your amazing image uploaded'))
return redirect('pyxchange:index')
context = {
'form': form,
'images_recent': images_recent,
'images_popular': images_popular,
'images_like': images_like
}
return render(request, 'pyxchange/index.html', context)
我在这里修复/添加了什么来解决问题?感谢。