app.py 文件源码

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

项目:TripMeal 作者: DanielAndreasen 项目源码 文件源码
def edit_recipe(rid):
    # Get the recipe
    # c.execute('INSERT INTO recipes (title, location, ingredients, recipe, user) VALUES ("%s", "%s", "%s", "%s", "%s");' %
    c, conn = connection()
    _ = c.execute('SELECT * FROM recipes WHERE rid="%s"' % rid)
    recipe = c.fetchone()
    c.close()
    conn.close()
    gc.collect()

    # Fill the form
    form = RecipeForm(request.form)
    form.title.data = recipe[1]
    form.country.data = recipe[2]
    form.ingredients.data = '\n'.join(recipe[3].split(','))
    form.recipe.data = recipe[4]

    if request.method == 'POST':
        title = escape_string(request.form['title'])
        country = escape_string(request.form['country'])
        ingredients = escape_string(','.join(request.form['ingredients'].split('\r\n')).strip(','))
        recipe = escape_string(request.form['recipe'])

        # Update the DB
        c, conn = connection()
        c.execute('UPDATE recipes SET title="%s", location="%s", ingredients="%s", recipe="%s" WHERE rid=%s' % (title, country, ingredients, recipe, rid))
        conn.commit()

        # Close connection
        c.close()
        conn.close()
        gc.collect()

        flash('Recipe updated')

        return redirect(url_for('user_page'))

    return render_template('edit_recipe.html', form=form)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号