def create_user(): username = prompt('用户名').strip() password = prompt_pass('密码').strip() repassword = prompt_pass('重复密码').strip() is_super = prompt_bool('是否超级用户') is_staff = prompt_bool('是否后台用户') if not all([username, password, repassword]): print('请填入完整信息') return if password != repassword: print('两次输入密码不一致') return connect_db() user = User() user.username = username user.password = password user.is_staff = is_staff user.is_super = is_super db_session.add(user) db_session.commit() print('创建用户成功')
def article_detail(id): article = Article.query.options(joinedload('replies')).get(id) if request.method == 'POST' and session.get('id'): content = request.form.get('content') reply = Reply() reply.user_id = session.get('id') reply.article = article reply.content = content db_session.commit() return redirect(url_for('.article_detail', id=id)) return render_template('article_detail.html', article=article)
def article_detail(id): article = Article.query.options(joinedload('replies')).get(id) if request.method == 'POST': if 'id' not in session: return redirect(url_for('.login')) reply = Reply() reply.user_id = session.get('id') reply.article = article reply.content = request.form['content'] db_session.commit() return render_template('detail.html', article=article)
def reply_again(id): if 'id' not in session: return json.dumps(dict(error='请先登陆')) reply = Reply() reply.user_id = session.get('id') reply.reply_again_id = id reply.content = request.form.get('content') db_session.add(reply) db_session.commit() macro = get_template_attribute('repeat_reply.html', 'repeat_reply') return json.dumps(dict(id=reply.id, content=macro(reply)))
def reply_again(id): if not session.get("id"): return json.dumps(dict(error="请先登陆")) reply = Reply() reply.user_id = session.get("id") reply.reply_id = id reply.content = request.form.get("content") db_session.add(reply) db_session.commit() macro = get_template_attribute("reply_again.html", "repeat_reply") return json.dumps(dict(id=reply.id, content=macro(reply)))
def detail(id): article = Article.query.options(joinedload("replies")).get(id) if request.method == "POST": if not session.get("id"): flash("请先登陆") elif not request.form.get("content"): flash("请输入评论信息") else: reply = Reply() reply.article = article reply.user_id = session.get("id") reply.content = request.form.get("content") db_session.commit() return redirect(url_for(".detail", id=id)) return render_template("article_detail.html", article=article)
def article_detail(id): article = Article.query.options(joinedload(Article.replies).joinedload(Reply.user)).get(id) if request.method == 'POST': if not session.get('id'): return redirect(url_for('.login')) content = request.form.get('content') if not content: flash('请填写内容') else: reply = Reply() reply.content = content reply.article = article reply.user_id = session.get('id') db_session.commit() return redirect(url_for('.article_detail', id=id)) return render_template('article_detail.html', article=article)
def register(): if request.method == 'POST': username = request.form['username'] password = request.form['password'] repassword = request.form['repassword'] if password != repassword: flash('两次输入密码不一致') elif check_exists(username): flash('用户已存在') else: user = User(username=username) user.password = password db_session.add(user) db_session.commit() return redirect(url_for('.login')) return render_template('register.html')
def reply_again(id): user_id = session.get('id') content = request.form.get('content') if not user_id: return json.dumps(dict(error='请先登陆!')) if not content: return json.dumps(dict(error='请输入评论信息!')) reply = Reply() reply.user_id = user_id reply.content = content reply.reply_id = id db_session.add(reply) db_session.commit() macro_func = get_template_attribute('reply_recursion.html', 'reply_again') return json.dumps(dict(id=reply.id, content=macro_func(reply)))
def register(): if request.method == 'POST': username = request.form.get('username') password = request.form.get('password') repassword = request.form.get('repassword') if password != repassword or not password: flash('两次密码不一致') elif User.query.filter_by(username=username).first(): flash('用户名已注册') else: user = User() user.username = username user.password = password db_session.add(user) db_session.commit() return redirect(url_for('.login')) return render_template('register.html')
def reply_again(): if not session.get('id'): return jsonify(error='请先登陆!') content = request.form.get('content') if not content: return jsonify(error='请填写内容') reply = Reply() reply.content = content reply.user_id = session.get('id') reply.reply_parent_id = request.form.get('id') db_session.add(reply) db_session.commit() macro = get_template_attribute('recurse.html', 'recurse_reply') return jsonify(content=macro(reply))
def reply_again(id): if not session.get('id'): return jsonify(error='请先登陆!') content = request.form.get('content') if not content: return jsonify(error='请输入完整信息!') reply = Reply() reply.user_id = session.get('id') reply.reply_id = id reply.content = content db_session.add(reply) db_session.commit() macro = get_template_attribute('replyAgain.html', 'replyAgain') return jsonify(id=reply.id, html=macro(reply))
def detail(id): article = Article.query.options(joinedload('replies')).get(id) if request.method == 'POST': if not session.get('id'): flash('请先登陆!') else: content = request.form.get('content') if not content: flash('请输入完整信息!') else: reply = Reply() reply.user_id = session.get('id') reply.article = article reply.content = content db_session.commit() return redirect(url_for('.detail', id=id)) return render_template('article_detail.html', article=article)
def reply_again(): if not session.get('id'): return jsonify(error='请先登陆') form = request.form if not form['content']: return jsonify(error='请填写信息') reply = Reply() reply.user_id = session.get('id') reply.content = form['content'] reply.reply_id = form['id'] db_session.add(reply) db_session.commit() macro = get_template_attribute('recurse.html', 'recurse') return jsonify(content=macro(reply))
def register(): if request.method == "POST": username = request.form.get("username").strip() password = request.form.get("password").strip() repassword = request.form.get("repassword").strip() if not all([username, repassword, password]): flash("请输入完整信息") elif User.query.filter_by(username=username).first(): flash("用户名已被使用") elif password != repassword: flash("两次输入密码不同") else: user = User() user.username = username user.password = password db_session.add(user) db_session.commit() return redirect(url_for(".login")) return render_template("register.html")
def register(): if request.method == 'POST': form = request.form username = form['username'] password = form['password'] repassword = form['repassword'] if not all([username, password, repassword]): flash('请填写完整信息!') elif password != repassword: flash('两次输入密码不一致!') else: user = User() user.username = username user.password = password db_session.add(user) db_session.commit() return redirect(url_for('.login')) return render_template('register.html')
def register(): if request.method == 'POST': form = request.form username = form.get('username') password = form.get('password') repassword = form.get('repassword') if not all([username, password, repassword]): flash('请填写完整信息') elif password != repassword: flash('两次输入密码不一致') elif User.query.filter(User.username==username).first(): flash('用户已存在') else: user = User() user.username=username user.password = password db_session.add(user) db_session.commit() return redirect(url_for('.login')) return render_template('register.html')