def change_article(): if request.method == 'GET': article_id = request.args.get('articleId') show = request.args.get('show') sql = 'select art.*, type.type_name from ' \ 't_article art, t_article_type type ' \ 'where art.type_id=type.type_id ' \ 'and art.article_id=%s' article = databaes.query_one(sql, (article_id, )) types = databaes.query_all('select * from t_article_type') if show: return jsonify(article) return render_template('change_article.html', article=article, types=types) else: article_id = request.form.get('articleId') title = request.form.get('title') article = request.form.get('article') type = request.form.get('type') print(type) print(article) sql = 'update t_article set title=%s, content=%s, type_id=%s where article_id=%s' row = databaes.update(sql, (title, article, type, article_id)) print(row) if row > 0: return 'ok' else: return 'error'
def delete_article(): article_id = request.args.get('articleId') row = databaes.update('delete from t_article where article_id=%s', (article_id, )) if row > 0: return redirect('/mgr_article') else: return '删除失败'
def delete_articles(): article_ids = request.args.get('articleIds') print(article_ids) sql = 'delete from t_article where article_id in (' + article_ids + ')' row = databaes.update(sql) if row > 0: return 'ok' else: return 'false'
def comment(): comment_text = request.form.get('commentText') user_id = request.form.get('userId') article_id = request.form.get('articleId') sql = 'insert into t_comment(content, user_id, article_id) values(%s, %s, %s)' row = databaes.update(sql, (comment_text, user_id, article_id)) if row > 0: return 'ok' else: return 'no'
def edit_article(): if request.method == 'POST': title = request.form.get('title') article = request.form.get('article') type = request.form.get('type') sql = 'insert into t_article(title, content, type_id) values(%s, %s, %s)' row = databaes.update(sql, (title, article, type)) if row > 0: return 'ok' else: return 'error' else: types = databaes.query_all('select * from t_article_type') return render_template('edit_article.html', types=types)
def regist(): if request.method == 'GET': return render_template('regist.html') else: username = request.form.get('username') password = request.form.get('password') confirm_pass = request.form.get('passwordconfirm') email = request.form.get('email') if username == '': return render_template('regist.html', email=email, error='用户名不能为空') elif password != confirm_pass: return render_template('regist.html', email=email, error='密码不一致') elif len(password) < 6: return render_template('regist.html', email=email, error='密码太短') sql = "insert into t_user(username, password, email) values(%s, %s, %s)" row = databaes.update(sql, (username, password, email)) if row > 0: return redirect(url_for('index')) else: return '注册失败'