django - 我无法在 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
})
解决方案
try using forward slash at the end of upload_to
path like this: upload_to='profile_pics/'
推荐阅读
- java - JAVA Swing:无法将文本附加到 TextArea
- xslt - XSLT 匹配多个条件
- javascript - 在某些月份停止增加和减少月份
- python - 有没有一种 Pythonic 方式来交互两个数据帧并比较它们的行?
- python - 奇怪的结果形式 stats.mannwhitneyu
- excel - Excel/VBA 是否优化冗余变量?
- react-native - 如何在 React Native 中自动链接依赖项的依赖项?
- c# - 无法将运算符“> =”应用于 X 类型的运算符和“浮点”
- javascript - A-Frame:我所有的孩子什么时候完全初始化?
- python - from torchvision import _C ImportError: DLL load failed: 找不到指定的模块