我创建使用瓶的论坛项目,并管理所有用户,主题,帖子等。然而,我发现,当我尝试做X(例如编辑后),我得到一个InvalidRequestError如果我尝试做别的事(例如删除后)。烧瓶SQLAlchemy的InvalidRequestError:目的是使用烧瓶SQLAlchemy的已经连接到会议
进行编辑后,
def post_edit(id, t_id, p_id):
post = Post.query.filter_by(id=p_id).first()
if post.author.username == g.user.username:
form = PostForm(body=post.body)
if form.validate_on_submit():
post.body = form.body.data
db.session.commit()
return redirect(url_for('thread', id=id, t_id=t_id))
return render_template('post_edit.html', form=form, title='Edit')
else:
flash('Access denied.')
return redirect(url_for('thread', id=id, t_id=t_id))
和删除后,
@app.route('/forum=<id>/thr=<t_id>/p=<p_id>/delete', methods=['GET','POST'])
def post_delete(id, t_id, p_id):
post = Post.query.filter_by(id=p_id).first()
if post.author.username == g.user.username:
db.session.delete(post)
db.session.commit()
return redirect(url_for('thread', id=id, t_id=t_id))
else:
flash('Access denied.')
return redirect(url_for('thread', id=id, t_id=t_id))
和张贴后
@app.route('/forum/id=<id>/thr=<t_id>', methods=['GET','POST'])
def thread(id, t_id):
forum = Forum.query.filter_by(id=id).first()
thread = Thread.query.filter_by(id=t_id).first()
posts = Post.query.filter_by(thread=thread).all()
form = PostForm()
if form.validate_on_submit():
post = Post(body=form.body.data,
timestamp=datetime.utcnow(),
thread=thread,
author=g.user)
db.session.add(post)
db.session.commit()
return redirect(url_for('thread', id=id, t_id=t_id))
return render_template('thread.html', forum=forum, thread=thread, posts=posts, form=form, title=thread.title)
不幸的是,唯一正确的方式,使这个问题解决本身就是重置实际运行应用程序的脚本,run.py
#!bin/python
from app import app
app.run(debug=True,host='0.0.0.0')
看起来像WhooshAlchemy的确是问题所在。至于符号,它只是一个简写“THR =”。 –
Ganye
2013-05-13 21:15:25
我的意思是“thr =”部分。但我想你可以做/ thr = 44/p = 32/c = 21种url格式,我只是觉得很奇怪。我很高兴我们发现了这个问题。 – Dexter 2013-05-14 06:08:41
就是这样;例如,论坛(1)中的特定主题(8)会创建url“/ forum/id = 1/thr = 8”。 – Ganye 2013-05-15 18:59:36