Skip to content

Commit 56466d1

Browse files
author
Jon Wayne Parrott
authored
Flask tutorial samples (GoogleCloudPlatform#391)
1 parent 3fd9905 commit 56466d1

File tree

18 files changed

+293
-7
lines changed

18 files changed

+293
-7
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lib
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# App Engine Standard Flask Hello World
2+
3+
This sample shows how to use [Flask](http://flask.pocoo.org/) with Google App
4+
Engine Standard.
5+
6+
Before running or deploying this application, install the dependencies using
7+
[pip](http://pip.readthedocs.io/en/stable/):
8+
9+
pip install -t lib -r requirements.txt
10+
11+
For more information, see the [App Engine Standard README](../../README.md)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
runtime: python27
2+
api_version: 1
3+
threadsafe: true
4+
5+
handlers:
6+
- url: /.*
7+
script: main.app
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2016 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from google.appengine.ext import vendor
16+
17+
# Add any libraries installed in the "lib" folder.
18+
vendor.add('lib')
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright 2016 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START app]
16+
import logging
17+
18+
from flask import Flask
19+
20+
21+
app = Flask(__name__)
22+
23+
24+
@app.route('/')
25+
def hello():
26+
return 'Hello World!'
27+
28+
29+
@app.errorhandler(500)
30+
def server_error(e):
31+
# Log the error and stacktrace.
32+
logging.exception('An error occurred during a request.')
33+
return 'An internal error occurred.', 500
34+
# [END app]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2016 Google Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import pytest
16+
17+
18+
@pytest.fixture
19+
def app():
20+
import main
21+
main.app.testing = True
22+
return main.app.test_client()
23+
24+
25+
def test_index(app):
26+
r = app.get('/')
27+
assert r.status_code == 200
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Flask==0.11
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lib
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# App Engine Standard Flask Tutorial App
2+
3+
This sample shows how to use [Flask](http://flask.pocoo.org/) to handle
4+
requests, forms, templates, and static files on Google App Engine Standard.
5+
6+
Before running or deploying this application, install the dependencies using
7+
[pip](http://pip.readthedocs.io/en/stable/):
8+
9+
pip install -t lib -r requirements.txt
10+
11+
For more information, see the [App Engine Standard README](../../README.md)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
runtime: python27
2+
api_version: 1
3+
threadsafe: true
4+
5+
# [START handlers]
6+
handlers:
7+
- url: /static
8+
static_dir: static
9+
- url: /.*
10+
script: main.app
11+
# [END handlers]

0 commit comments

Comments
 (0)