movie没有tag元素
来源:7-8 .电影管理-列表-删除-编辑1
慕哥3993229
2017-08-11
AttributeError: 'Movie' object has no attribute 'tag'
报错提示没有tag属性。
之后我把movie_list.htl里面的 {{v.tag.name}}删除后就不报错
电影列表视图函数如下
#电影列表
@admin.route('/movie/list/<int:page>/',methods=['GET'])
@admin_login_req
def movie_list(page=None):
if page is None:
page = 1
page_data = Movie.query.join(Tag).filter(
Tag.id == Movie.tag_id
).order_by(
Movie.addtime.desc()
).paginate(page=page, per_page=10)
return render_template('admin/movie_list.html', page_data=page_data)
2回答
-
亲,你试一下大写{{ v.Tag.name }}
052017-08-12 -
慕哥3993229
提问者
2017-08-11
###models.py
# 标签
class Tag(db.Model):
__tablename__ = 'tag'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(100), unique=True)
addtime = db.Column(db.DateTime, index=True, default=datetime.utcnow)
movies = db.relationship('Movie', backref='tag')
def __repr__(self):
return '<Tag:%r>' % self.name
# 电影
class Movie(db.Model):
__tabalename__ = 'movie'
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(255), unique=True)
url = db.Column(db.String(255), unique=True)
info = db.Column(db.Text)
logo = db.Column(db.String(255), unique=True)
star = db.Column(db.SmallInteger)
playnum = db.Column(db.BigInteger)
commentnum = db.Column(db.BigInteger)
tag_id = db.Column(db.Integer, db.ForeignKey('tag.id'))
area = db.Column(db.String(255))
releasetime = db.Column(db.Date)
length = db.Column(db.String(100))
addtime = db.Column(db.DateTime, index=True, default=datetime.utcnow)
comments = db.relationship('Comment', backref='movie')
moviecols = db.relationship('MovieCol', backref='movie')
def __repr__(self):
return '<Movie:%r>' % self.title###admin/views.py
#电影列表
@admin.route('/movie/list/<int:page>/',methods=['GET'])
@admin_login_req
def movie_list(page=None):
if page is None:
page = 1
page_data = Movie.query.join(Tag).filter(
Tag.id == Movie.tag_id
).order_by(
Movie.addtime.desc()
).paginate(page=page, per_page=10)
return render_template('admin/movie_list.html', page_data=page_data)###html
{% for v in page_data.items %}
<tr>
<td>{{ v.id }}</td>
<td>{{ v.title }}</td>
<td>{{ v.length }}分钟</td>
<td>{{ v.Tag.name }}</td>
<td>{{ v.area }}</td>
<td>{{ v.star }}</td>
<td>{{ v.playnum }}</td>
<td>{{ v.commentnum }}</td>
<td>{{v.addtime}}</td>
<td>
<a class="label label-success">编辑</a>
<a class="label label-danger">删除</a>
</td>
</tr>
{% endfor %}00
相似问题