-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jon Wayne Parrott
committed
Jun 29, 2016
1 parent
3fd9905
commit 56466d1
Showing
18 changed files
with
293 additions
and
7 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lib |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# App Engine Standard Flask Hello World | ||
|
||
This sample shows how to use [Flask](http://flask.pocoo.org/) with Google App | ||
Engine Standard. | ||
|
||
Before running or deploying this application, install the dependencies using | ||
[pip](http://pip.readthedocs.io/en/stable/): | ||
|
||
pip install -t lib -r requirements.txt | ||
|
||
For more information, see the [App Engine Standard README](../../README.md) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
runtime: python27 | ||
api_version: 1 | ||
threadsafe: true | ||
|
||
handlers: | ||
- url: /.* | ||
script: main.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright 2016 Google Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from google.appengine.ext import vendor | ||
|
||
# Add any libraries installed in the "lib" folder. | ||
vendor.add('lib') |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright 2016 Google Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# [START app] | ||
import logging | ||
|
||
from flask import Flask | ||
|
||
|
||
app = Flask(__name__) | ||
|
||
|
||
@app.route('/') | ||
def hello(): | ||
return 'Hello World!' | ||
|
||
|
||
@app.errorhandler(500) | ||
def server_error(e): | ||
# Log the error and stacktrace. | ||
logging.exception('An error occurred during a request.') | ||
return 'An internal error occurred.', 500 | ||
# [END 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright 2016 Google Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def app(): | ||
import main | ||
main.app.testing = True | ||
return main.app.test_client() | ||
|
||
|
||
def test_index(app): | ||
r = app.get('/') | ||
assert r.status_code == 200 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Flask==0.11 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lib |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# App Engine Standard Flask Tutorial App | ||
|
||
This sample shows how to use [Flask](http://flask.pocoo.org/) to handle | ||
requests, forms, templates, and static files on Google App Engine Standard. | ||
|
||
Before running or deploying this application, install the dependencies using | ||
[pip](http://pip.readthedocs.io/en/stable/): | ||
|
||
pip install -t lib -r requirements.txt | ||
|
||
For more information, see the [App Engine Standard README](../../README.md) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
runtime: python27 | ||
api_version: 1 | ||
threadsafe: true | ||
|
||
# [START handlers] | ||
handlers: | ||
- url: /static | ||
static_dir: static | ||
- url: /.* | ||
script: main.app | ||
# [END handlers] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright 2016 Google Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from google.appengine.ext import vendor | ||
|
||
# Add any libraries installed in the "lib" folder. | ||
vendor.add('lib') |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Copyright 2016 Google Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# [START app] | ||
import logging | ||
|
||
# [START imports] | ||
from flask import Flask, render_template, request | ||
# [END imports] | ||
|
||
app = Flask(__name__) | ||
|
||
|
||
# [START form] | ||
@app.route('/form') | ||
def form(): | ||
return render_template('form.html') | ||
# [END form] | ||
|
||
|
||
# [START submitted] | ||
@app.route('/submitted', methods=['POST']) | ||
def submitted_form(): | ||
name = request.form['name'] | ||
email = request.form['email'] | ||
site = request.form['site_url'] | ||
comments = request.form['comments'] | ||
|
||
# [END submitted] | ||
# [START render_template] | ||
return render_template( | ||
'submitted_form.html', | ||
name=name, | ||
email=email, | ||
site=site, | ||
comments=comments) | ||
# [END render_template] | ||
|
||
|
||
@app.errorhandler(500) | ||
def server_error(e): | ||
# Log the error and stacktrace. | ||
logging.exception('An error occurred during a request.') | ||
return 'An internal error occurred.', 500 | ||
# [END 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright 2016 Google Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def app(): | ||
import main | ||
main.app.testing = True | ||
return main.app.test_client() | ||
|
||
|
||
def test_form(app): | ||
r = app.get('/form') | ||
assert r.status_code == 200 | ||
assert 'Submit a form' in r.data.decode('utf-8') | ||
|
||
|
||
def test_submitted_form(app): | ||
r = app.post('/submitted', data={ | ||
'name': 'Inigo Montoya', | ||
'email': 'inigo@example.com', | ||
'site_url': 'http://example.com', | ||
'comments': ''}) | ||
assert r.status_code == 200 | ||
assert 'Inigo Montoya' in r.data.decode('utf-8') |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Flask==0.11 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.pagetitle { | ||
color: #800080; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<html> | ||
<head> | ||
<title>Submit a form</title> | ||
<link rel="stylesheet" type="text/css" href="/static/style.css"> | ||
</head> | ||
<body> | ||
<div id="container"> | ||
<div class="pagetitle"> | ||
<h1>Submit a form</h1> | ||
</div> | ||
<div id="main"> | ||
<form method="post" action="{{ url_for('submitted_form') }}"> | ||
<label for="name">Name:</label> | ||
<input type="text" name="name"><br /> | ||
<label for="email">Email address:</label> | ||
<input type="email" name="email"><br /> | ||
<label for="site_url">Website URL:</label> | ||
<input type="url" name="site_url"><br /> | ||
<label for="comments">Comments:</label> | ||
<textarea name="comments"></textarea><br /> | ||
<input type="submit"> | ||
</form> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
23 changes: 23 additions & 0 deletions
23
appengine/standard/flask/tutorial/templates/submitted_form.html
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<html> | ||
<head> | ||
<title>Submitted form</title> | ||
<link rel="stylesheet" type="text/css" href="/static/style.css"> | ||
</head> | ||
<body> | ||
<div id="container"> | ||
<div class="pagetitle"> | ||
<h1>Form submitted</h1> | ||
</div> | ||
<div id="main"> | ||
<p>Thanks for your submission, {{name}}!</p> | ||
<p>Here's a review of the information that you sent:</p> | ||
<p> | ||
<strong>Name</strong>: {{name}} <br> | ||
<strong>Email</strong>: {{email}} <br> | ||
<strong>Website URL</strong>: {{site}} <br> | ||
<strong>Comments</strong>: {{comments}} | ||
</p> | ||
</div> | ||
</div> | ||
<body> | ||
</html> |
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