Created
April 22, 2019 16:29
-
-
Save littlebenlittle/dc92599cd9c88674d6308e8a908ed2d6 to your computer and use it in GitHub Desktop.
Handling multiple routes with App Engine python37 runtime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request | |
import sys | |
app = Flask(__name__) | |
@app.route('/api/test', methods=['GET', 'POST']) | |
def test(): | |
content = '<p>handler: ' + sys._getframe(0).f_code.co_name + \ | |
'</p>\n<ul>\n' | |
if request.method == 'POST': | |
for k, v in request.form.to_dict().items(): | |
content += '<li>' + k + ': ' + v + '</li>\n' | |
content += '</ul>' | |
return """ | |
<html> | |
<body> | |
<h1>test</h1> | |
{} | |
</body> | |
</html> | |
""".format(content) | |
@app.route('/api/auth/google', methods=['GET', 'POST']) | |
def google_auth(): | |
pass | |
if __name__ == '__main__': | |
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
runtime: python37 | |
entrypoint: gunicorn -b :$PORT api:app spa:app | |
handlers: | |
- url: /static | |
static_dir: app/dist/static | |
- url: /api/.* | |
script: api.app | |
- url: /.* | |
script: spa.app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, render_template | |
import os | |
app = Flask( | |
__name__, | |
static_folder = "./app/dist/static", | |
template_folder = "./app/dist", | |
) | |
@app.route('/') | |
def get(): | |
return render_template("index.html") | |
if __name__=='__main__': | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment