我正在使用slugify,并且我不知道如何让我的帖子标题重新开始,我是否需要在我的帖子中创建一个新列?我一整天都被困在这里。你怎么slugify一个网址?
有什么建议吗?
Views.py
@app.route('/posts/<title>')
@login_required
def show(title):
link = db.session.query(Post).filter_by(title = title).one()
link2 = slugify(link.title)
return render_template("post.html", post=link2, pid=id, title=link2)
Models.py
class Post(db.Model):
__tablename__ = "posts"
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(80))
body = db.Column(db.Text)
def __init__(self, title, body):
self.title = title
self.body = body
错误信息
File "C:\Program Files\Python35-32\lib\site-packages\sqlalchemy\orm\query.py", line 2760, in one
raise orm_exc.NoResultFound("No row was found for one()")
sqlalchemy.orm.exc.NoResultFound: No row was found for one()
尝试洛'title'。它是否被正确接收? –
错误只是说它找不到任何行,而您期望一行。我通常使用'Post.query.filter_by(title = title).first()',然后检查结果是否为null。 –
@btquanto你能改说我不明白吗? –