小编Bra*_*mel的帖子

类型错误:解析器必须是字符串或字符流,而不是日期时间

我试图让一个网页显示数据库中列出的所有即将上映的节目,以及分别存储在场地和艺术家表中的关于每个节目的一堆信息。我查询 Show 表,然后为该结果中的每一行链接 Artist 和 Venue 表。因为错误有事情做与日期时间,我假设的错误是与任一if show.start_time > current_time:"start_time": show.start_time但误差不拖住它在哪里。我尝试将 current_time 和 show.start_time 都转换为字符串,看看是否有效,但没有运气。我究竟做错了什么?

@app.route('/shows')
def shows():

  current_time = datetime.now()

  data = []

  allshows = Show.query.all()

  for show in allshows:
    artist = Artist.query.get(show.artist_id)
    venue = Venue.query.get(show.venue_id)

    if show.start_time > current_time:
      data.append({
        "venue_id": show.venue_id,
        "venue_name": venue.name,
        "artist_id": show.artist_id,
        "artist_name": artist.name,
        "artist_image_link": artist.image_link,
        "start_time": show.start_time
      })
 
  return render_template('pages/shows.html', shows=data)
Run Code Online (Sandbox Code Playgroud)

如果有帮助,以下是与之相关的模型:

class Venue(db.Model):
    __tablename__ = 'venues'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String)
    city = db.Column(db.String(120))
    state = …
Run Code Online (Sandbox Code Playgroud)

python sqlalchemy

0
推荐指数
1
解决办法
2881
查看次数

标签 统计

python ×1

sqlalchemy ×1