简体   繁体   English

Django 更新个人资料照片

[英]Django updating profile photo

Look I have a problem with displaying photos after updating.看我更新后显示照片有问题。

I have a function from my views.py我的 views.py 中有一个函数

def addHW(request):
    if request.user.is_authenticated:
        obj = Profile.objects.get(user=request.user.id)
    else:
        obj = ''
    profile = request.user.profile
    form = CustomerForm(instance=profile)
    template = 'HW/add.html'
    context = {'form': form, 'profile': obj}

    if request.method == 'POST':
        form = CustomerForm(request.POST, request.FILES, instance=profile)
        if form.is_valid():
            Profile.objects.get(user=request.user.id).photo.delete()
            form.save()

    return render(request, template, context)

and after deleting previous photo and saving of new photo, page must be reloaded.删除以前的照片并保存新照片后,必须重新加载页面。 And page shows visual reloading, but HTML shows src of previous image.页面显示视觉重新加载,但 HTML 显示前一个图像的 src。 And after manual refreshing page displays new src of photo.并在手动刷新页面后显示照片的新 src。 How i can resolve it?我该如何解决?

In case of a successful post, you need to make a redirect to implement the Post/Redirect/Get pattern.如果发布成功,您需要进行重定向以实现 Post/Redirect/Get 模式。 – Willem Van Onsem 32 mins ago – Willem Van Onsem 32 分钟前

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM