Flask Web 开发 用户资料_2
来源:互联网 发布:mac英国官网 编辑:程序博客网 时间:2024/05/16 13:49
继续上一篇章
有了用户资料的页面,那总归要可以编辑吧,那编辑就涉及到通过表单来提交
所以,我们又要来新建一个Form了
main/forms.py
from flask.ext.wtf import Formfrom wtforms import StringField,SubmitField,TextAreaFieldfrom wtforms.validators import Required,Lengthclass EditProfileForm(Form):name = StringField('Real name',validators=[Length(0,64)]) #这里Length设置(0,64)的意思是可选项,不一定必填location = StringField('Location',validators=[Length(0,64)])about_me = TextAreaField('About me') #TextAreaField,一个文本框功能submit = SubmitField('Submit')
@main.route('/edit-profile',methods=['GET','POST'])@login_requireddef edit_profile():form = EditProfileForm()if form.validate_on_submit():current_user.name = form.name.datacurrent_user.location = form.location.datacurrent_user.about_me = form.about_me.datadb.session.add(current_user)flash('Your profile has been updated')return redirect(url_for('.user',username = current_user.username))form.name.data = current_user.name #注意以下三行的缩进,这三行的功能是让表单在没有提交或者提交失败的情况下form.location.data = current_user.location #显示的内容是预设值,而预设值就是在提交之前,current_user的各项属性值form.about_me.data = current_user.about_mereturn render_template('edit_profile.html',form = form)
然后,作者在制作Edit Profile按钮的时候,设置了一个条件语句,这样做的目的是,只有当用户是你自己时候,才能生成这个链接
app/templates/user.html
{% if user == current_user %}<a class="btn btn-default" href="{{ url_for('.edit_profile') }}">Edit Profile</a>{% endif %}
点击以后,就可以修改你的个人资料了
由于国内google被墙,所以地图的对应我改成百度的了
修改完以后,就可以看到下面的效果图了,我红线标注的地方是将地图导航改成百度的地图.
0 0
- Flask Web 开发 用户资料_2
- Flask Web 开发 用户认证_2
- Flask Web 开发 用户评论_2
- Flask Web 开发 用户资料
- Flask Web 开发 用户资料_3
- Flask Web 开发 用户资料_4
- Flask Web 开发 Web表单_2
- Flask Web 开发 博客文章_2
- Flask Web 开发 关注者_2
- Flask Web 开发 用户认证
- Flask Web 开发 用户角色
- Flask Web 开发 用户评论
- [python3.6 flask web学习]Flask用户资料管理
- Flask Web 开发 用户认证_3
- Flask Web 开发 用户认证_4
- Flask Web 开发 用户认证_5
- Flask Web 开发 用户认证_6
- 《flask web开发》第八章 用户认证
- 读取纯真IP数据库C++源代码
- IOS-- UIView中的坐标转换
- 安卓项目知识小结系列——2016年9月1日
- 逐梦旅程-2016-09-01
- eclipse中使用svn(详细)
- Flask Web 开发 用户资料_2
- 【jsp/servlet】jsp开发基础
- fastDFS和nginx环境搭建和java上传图片demo
- jquery之empty()与remove()区别
- POJ 1118Lining Up【几何】
- Google Map API获取给定地址经纬度并显示
- ISCSS 项目开始开发了
- Intent学习(2)
- Android APP安全评估工具Drozer PC端重要代码解析