def post(): longitude = request.form.get('longitude', '') latitude = request.form.get('latitude', '') treasure = request.form.getlist('treasure') if not (isfloat(latitude) and isfloat(longitude) and treasure): return redirect('/post.html') try: tags = [Tag.get(tag=x) for x in treasure] except Tag.DoesNotExist: return redirect('/post.html') x, obj_created = Point.get_or_create( latitude=latitude, longitude=longitude, defaults={'treasure': ', '.join(treasure)}) # type:Point,bool if obj_created: for y in tags: PointTag.create(tag=y, point=x) l = LogPoint.create(latitude=latitude, longitude=longitude, treasure=', '.join(treasure), created_date=x.created_date) else: return render_template('post.html', tags=Tag.select().execute(), message='坐标已存在') # return render_template('post.html') # return '坐标已存在 <a href="/post.html">重新分享</a>' return redirect('/')