首页 > 解决方案 > 我无法在 django 中更改个人资料图片

问题描述

我在 models.py 和 form.py 中创建了一个配置文件表单来更新它,但是除了配置文件图片 views.py之外所有的东西都得到了更新

视图.py

@login_required
def update_profile(request):
    if request.method == 'POST':
        profile_form = ProfileForm(request.POST, request.FILES, instance=request.user.profile)
        if profile_form.is_valid():
            profile_form.save()
            messages.success(request, "Your profile updated.")
        else:
            status_code = 400
            message = 'Please correct the error below.'
            messages.error(request, "Please use correct information")
    else:
        profile_form = ProfileForm(instance=request.user.profile)
    return render(request, 'profile.html', {
        'profile_form': profile_form
    })

表格.py

模型.py

标签: djangodjango-modelsdjango-rest-frameworkdjango-viewsdjango-forms

解决方案


try using forward slash at the end of upload_to path like this: upload_to='profile_pics/'


推荐阅读