server.py 文件源码

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

项目:planty 作者: agnaite 项目源码 文件源码
def process_new_plant():
    """Gets the user input from new plant form and adds to the database"""

    # if user did not add image url, get one from flickr
    name = request.form.get('name')
    image = request.form.get('image')

    if not image:
        image = get_flickr_image(name)

    # gets plant info from angular's data passed in and creates new Plant instance
    new_plant = Plant(name=name,
                      species=request.form.get('species'),
                      image=image,
                      water=request.form.get('water'),
                      sun=request.form.get('sun'),
                      humidity=request.form.get('humidity'),
                      temperature=request.form.get('temp'))

    # adds plant to the database and saves
    db.session.add(new_plant)
    db.session.commit()

    # returns plant ID to angular's callback
    return str(new_plant.plant_id)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号