views.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:two_pic 作者: onlyonebowman 项目源码 文件源码
def index():

    # Grab the choice variable passed from POST
    # for x in request.args['choice']:
    #   print('in args: {}'.format(x))

    # hook up database functions
    Session = sessionmaker()

    # locate the db location; currently hardcoded to development database
    engine = create_engine('sqlite:///' + os.path.join(basedir, 'data-dev.sqlite'))
    Session.configure(bind=engine)
    session = Session()

    post_count = session.query(func.count(Post.id)).scalar()  # count number of unique posts in the table
    pic1 = Post.query.get(randint(1, post_count))  # fails if there is 1 or less entries in the database
    pic2 = None
    while pic2 == pic1 or pic2 is None:  # Don't pick the same file
        pic2 = Post.query.get(randint(1, post_count))

    pic1_filename = url_for('static', filename=pic1.filename)
    pic2_filename = url_for('static', filename=pic2.filename)

    return render_template('index.html', pic1=pic1, pic2=pic2, pic1_filename=pic1_filename, pic2_filename=pic2_filename)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号