- プロジェクトの作成 ~ デプロイ
Getting Started with Flask on App Engine Standard Environment - NDB Key Class : Context, Future, Key, Model, Query, PolyModel, Metadata, Function, Exceptions
- Entity Property Reference : BlobKeyProperty, BlobProperty, BooleanProperty, ComputedProperty, DateProperty, DateTimeProperty, FloatProperty, GenericProperty, GeoPtProperty, IntegerProperty, JsonProperty, KeyProperty, LocalStructuredProperty, PickleProperty, StringProperty, StructuredProperty, TextProperty, TimeProperty, UserProperty
- Template Designer Documentation ; Jinja2 Documentation (2.10)
# coding: utf-8 # https://issuetracker.google.com/issues/72043776#comment7 import os import sys on_appengine = os.environ.get('SERVER_SOFTWARE','').startswith('Development') if on_appengine and os.name == 'nt': sys.platform = "Not Windows" from google.appengine.ext import vendor # Add any libraries installed in the "lib" folder. vendor.add('lib')
エラー発生時に、コンソール画面へスタックトレースを表示したい
# https://stackoverflow.com/a/46914462 app = Flask(__name__) import os production_environment = os.getenv('SERVER_SOFTWARE').startswith('Google App Engine/') if not production_environment: app.debug = True空のレスポンス
# https://stackoverflow.com/a/24295616 return ('', 201)Key のパースエラーを包み隠す
try: key = ndb.Key(urlsafe = request.args.get('k')) except Exception, e: # https://github.com/googlecloudplatform/datastore-ndb-python/issues/143#issuecomment-110869342 if e.__class__.__name__ == 'ProtocolBufferDecodeError': return ('', 404) raiseContent-Type を設定
resp = Response("\n".join(lines)) resp.headers["content-type"] = 'text/plain' return respJinja2 で三項演算子。loop.first ? 'true' : 'false' 。参考
{{ 'true' if loop.first else 'false' }}?? 演算子も。
{{ value or 'fallback' }}
JSON を返す。参考
from flask import jsonify return jsonify(root)自分の URL 参考
from flask import request request.base_url
a
a
a