item_handler.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:github-catalog 作者: yogykwan 项目源码 文件源码
def new_item(category):
    if request.method == 'GET':
        return render('newitem.html', category=category)
    elif request.method == 'POST':
        name = request.form['name']
        highlight = request.form['highlight']
        url = request.form['url']
        if valid_item(name, url, highlight):
            user_id = login_session['user_id']
            item = Item(name=name, highlight=highlight, url=url, user_id=user_id, category_id=category.id)
            session.add(item)
            session.commit()
            flash("Newed item %s!" % item.name)
            return redirect(url_for('show_item', category_id=category.id, item_id=item.id))
        else:
            error = "Complete info please!"
            return render('newitem.html', category=category, name=name, highlight=highlight, url=url,
                          error=error)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号