Error during template rendering In template C:\Users\charlie...error at line 252 The 'image' attribute has no file associated with it

Viewed 15

When a user posts a picture, it's supposed to appear in the home page but instead it gives me this error. this is my function in views.py

@login_required(login_url='signin') def upload(request):

if request.method == 'POST':
    user = request.user.username
    image = request.FILES.get('image_upload')
    caption = request.POST['caption']

    new_post = Post.objects.create(user=user, image=image, caption=caption)
    new_post.save()

    return redirect('/')

else:
    return redirect('/')

The image can be seen in the admin panel but it won't appear on the home page. here is my django template tag

0 Answers
Related