0

我尝试更新数据库中的现有行。当我提交表单时,我被定向到触发 404 的 /item/edit/。我在不同的项目中有类似的代码并且可以正常工作。我不知道这有什么问题。

@main.route('/item/edit/<string:url>', methods = ['GET', 'POST'])
@login_required
def edit_item(url):
  i = get_item_by_url(url)
  form = ItemForm(obj=i)
  if form.validate_on_submit():
    i.title = form.title.data
    i.url = form.url.data
    i.body = form.body.data
    i.email = form.email.data
    i.private = form.private.data
    file = request.files['itempic']
    if file and allowed_file(file.filename):
      filename = secure_filename(file.filename)
      file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
      i.itempic = filename
    db.session.add(i)
    db.session.commit()
    flash('The Item: %s, has been updated succesfully.' % form.url.data)
    return redirect(url_for("index"))
  return render_template('/item/edit.html',
    form = form,
    i = i)
4

1 回答 1

1

问题是您的方法被映射到/item/edit/something-here并将something-here被映射到url变量。

当您请求/item/edit/它时,它不会映射到任何东西,所以它会引发 404。

于 2013-03-23T16:11:30.320 回答