12 2017 档案

摘要:模型分离--让代码更方便管理 新建models.py,将模型定义全部放到这个独立的文件中。 新建exts.py,将db = SQLAlchemy()的定义放到这个独立的文件中。 models.py和主py文件,都从exts.py中导入db。 在主py文件中,对db进行始化,db.init_app(a 阅读全文
posted @ 2017-12-26 11:13 055刘柏坚 阅读(148) 评论(0) 推荐(0) 编辑
摘要:1.更新User对象,设置对内的_password class User(db.Model): __tablename__ = 'user' _password = db.Column(db.String(200), nullable=False) #内部使用 2.编写对外的password fro 阅读全文
posted @ 2017-12-22 18:28 055刘柏坚 阅读(116) 评论(0) 推荐(0) 编辑
摘要:准备视图函数search() 修改base.html 中搜索输入框所在的 <form action="{{ url_for('search') }}" method="get"> <input name="q" type="text" placeholder="请输入关键字"> 完成视图函数sear 阅读全文
posted @ 2017-12-20 21:56 055刘柏坚 阅读(163) 评论(0) 推荐(0) 编辑
摘要:个人中心—视图函数带标签页面参数tag@app.route('/usercenter/<user_id>/<tag>')def usercenter(user_id, tag): if tag == ‘1': return render_template('usercenter1.html', ** 阅读全文
posted @ 2017-12-20 19:16 055刘柏坚 阅读(141) 评论(0) 推荐(0) 编辑
摘要:新页面userbase.html,用 实现标签页导航。 Home Profile Messages 让userbase.html继承base.html。重写title,head,main块.将上述的样式放在head块,放在main块中.定义新的块user。 让上次作业完成的个人中心页面,继承userbase.html,原个人中心就自动有了标签页导航。 制作个人中心的三个子页面,重写user... 阅读全文
posted @ 2017-12-16 18:37 055刘柏坚 阅读(137) 评论(0) 推荐(0) 编辑
摘要:定义评论的视图函数@app.route('/comment/',methods=['POST'])def comment():读取前端页面数据,保存到数据库中 用<input type="hidden" 方法获取前端的"question_id" 显示评论次数 要求评论前登录 尝试实现详情页面下的评论 阅读全文
posted @ 2017-12-13 19:23 055刘柏坚 阅读(149) 评论(0) 推荐(0) 编辑
摘要:定义评论的视图函数@app.route('/comment/',methods=['POST'])def comment():读取前端页面数据,保存到数据库中 用<input type="hidden" 方法获取前端的"question_id" 显示评论次数 要求评论前登录 尝试实现详情页面下的评论 阅读全文
posted @ 2017-12-08 21:22 055刘柏坚 阅读(164) 评论(0) 推荐(0) 编辑
摘要:主PY文件写视图函数,带id参数。 @app.route('/detail/<question_id>')def detail(question_id): quest = return render_template('detail.html', ques = quest) 首页标题的标签做带参数的 阅读全文
posted @ 2017-12-07 18:38 055刘柏坚 阅读(167) 评论(0) 推荐(0) 编辑
摘要:首页列表显示全部问答: 将数据库查询结果传递到前端页面 Question.query.all() 前端页面循环显示整个列表。 问答排序 完成问答详情页布局: 包含问答的全部信息 评论区 以往评论列表显示区。 在首页点击问答标题,链接到相应详情页。 py: @app.route('/') def in 阅读全文
posted @ 2017-12-06 18:38 055刘柏坚 阅读(162) 评论(0) 推荐(0) 编辑
摘要:在首页添加显示问答的列表,并定义好相应的样式。 无序列表 <ul > <li>Coffee</li> <li>Tea</li> <li>Milk</li> </ul> 2. 用字典向index.html传递参数。 py: def index(): context = { 'question':'he 阅读全文
posted @ 2017-12-01 12:52 055刘柏坚 阅读(156) 评论(0) 推荐(0) 编辑