用户头像无法显示?
来源:9-3 .修改会员资料
戴晶kyle
2017-12-19
老师,我的用户头像是存在的,但无法显示?
<div class="form-group"> <label for="input_face"> <span class="glyphicon glyphicon-picture"></span> {{form.face.label}} </label> {{form.face}} {% if user.face %} <img src="{{url_for('static',filename='uploads/users/'+user.face)}}" style="width:100px" class="img-responsive img-rounded"> {% else %} <img data-src="holder.js/100x100" class="img-responsive img-rounded"> {% endif %} </div>
#会员资料修改 @home.route('/user',methods=['GET','POST']) @user_login_req def user(): form=UserdetailForm() user=User.query.get(int(session['user_id'])) form.face.validators=[] if request.method=='GET': form.name.data=user.name form.email.data = user.email form.phone.data = user.phone form.info.data = user.info if form.validate_on_submit(): data=form.data file_face=secure_filename(form.face.data.filename) if not os.path.exists(app.config['FC_DIR']): os.makedirs(app.config['FC_DIR']) os.chmod(app.config['FC_DIR'],'rw') user.face=change_filename(file_face) form.face.data.save(app.config['FC_DIR']+user.face) name_count=User.query.filter_by(name=data['name']).count() if name_count==1 and data['name']!=user.name: flash('昵称已存在!','err') return redirect(url_for('home.user')) email_count = User.query.filter_by(email=data['email']).count() if email_count == 1 and data['email'] != user.email: flash('邮箱已存在!', 'err') return redirect(url_for('home.user')) phone_count = User.query.filter_by(phone=data['phone']).count() if phone_count == 1 and data['phone'] != user.phone: flash('手机号码已存在!', 'err') return redirect(url_for('home.user')) user.name = data['name'] user.email = data['email'] user.phone = data['phone'] user.info=data['info'] db.session.add(user) db.session.commit() flash('修改成功', 'ok') return redirect(url_for('home.user')) return render_template('home/user.html',form=form,user=user)
写回答
1回答
-
戴晶kyle
提问者
2017-12-19
自己解决了:
if form.validate_on_submit(): data=form.data if not os.path.exists(app.config['FC_DIR']): os.makedirs(app.config['FC_DIR']) os.chmod(app.config['FC_DIR'],'rw') if form.face.data.filename!='': file_face = secure_filename(form.face.data.filename) user.face=change_filename(file_face) form.face.data.save(app.config['FC_DIR']+user.face)
增加form.face.data.filename!=''的判断
00
相似问题