usercenter-info.html中修改头像部分的FORM
<form class="clearfix" id="jsAvatarForm" enctype="multipart/form-data" autocomplete="off" method="post" action="{% url 'users:image_upload' %}" target='frameFile'> <label class="changearea" for="avatarUp"> <span id="avatardiv" class="pic"> <img width="100" height="100" class="js-img-show" id="avatarShow" src="{{ MEDIA_URL }}{{ request.user.image }}"/> </span> <span class="fl upload-inp-box" style="margin-left:70px;"> <span class="button btn-green btn-w100" id="jsAvatarBtn">修改头像</span> <input type="file" name="image" id="avatarUp" class="js-img-up"/> </span> </label> <input type='hidden' name='csrfmiddlewaretoken' value='799Y6iPeEDNSGvrTu3noBrO4MBLv6enY' /> {% csrf_token %} </form>
users中urls中的配置
urlpatterns = [ #用户信息 url(r'^info/$', UserinfoView.as_view(), name="user_info"), #用户头像上传 url(r'^image/upload/$', UploadImageView.as_view(), name="image_upload"), #个人用户中心修改密码 url(r'^update/pwd/$', UpdatePwdView.as_view(), name="update_pwd"), ]
users中Vieww的配置
class UploadImageView(LoginRequiredMixin, View): """ 用户修改头像 """ def post(self, request): image_form = UploadImageForm(request.POST, request.FILES, instance=request.user) if image_form.is_valid(): image_form.save() return HttpResponse('{"status":"success", "msg":""}', content_type='application/json') else: return HttpResponse('{"status":"fail", "msg":""}', content_type='application/json')
打断点上传头像,反应都没有,感觉没发出POST请求?但是好像没有配置错啊?
登录后可查看更多问答,登录/注册