Skip to content

Commit 8a50b66

Browse files
committed
Merge pull request #231 from cloudControl/guides_update_flask
Update the Flask documentation
2 parents 4d9ec77 + 8d5dfab commit 8a50b66

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

Guides/Python/HelloWorld.md

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ $ git clone https://github.com/cloudControl/python-flask-example-app.git
1616
$ cd python-flask-example-app
1717
~~~
1818

19-
Now you have a small but fully functional Flask application.
19+
The code from the example repository is ready to be deployed. Lets still go
20+
through the different files and their purpose real quick.
2021

2122
### Dependency Tracking
2223
The Python buildpack tracks dependencies via pip and the `requirements.txt` file. It needs to be placed in the root directory of your repository. The example app specifies only Flask itself as a dependency and looks like this:
2324

2425
~~~pip
25-
Flask==0.9
26+
Flask==0.10.1
2627
~~~
2728

2829
### Process Type Definition
@@ -36,6 +37,27 @@ web: python server.py
3637

3738
Left from the colon we specified the **required** process type called `web` followed by the command that starts the app and listens on the port specified by the environment variable `$PORT`.
3839

40+
###The Actual Application Code
41+
42+
The actual application code is really straight forward. We import the required
43+
modules and create an instance of the class. Next we set the routes to trigger
44+
our hello() function which will then render the jinja template.
45+
46+
~~~python
47+
import os
48+
from flask import Flask, render_template
49+
50+
app = Flask(__name__)
51+
52+
53+
@app.route('/')
54+
def hello():
55+
return render_template('hello.jinja', domain=os.environ['DOMAIN'])
56+
57+
app.debug = True
58+
app.run(host='0.0.0.0', port=int(os.environ['PORT']))
59+
~~~
60+
3961
## Pushing and Deploying the App
4062
Choose a unique name to replace the `APP_NAME` placeholder for your application and create it on the cloudControl platform:
4163

@@ -47,25 +69,25 @@ Push your code to the application's repository, which triggers the deployment im
4769

4870
~~~bash
4971
$ cctrlapp APP_NAME/default push
50-
Counting objects: 16, done.
51-
Delta compression using up to 4 threads.
52-
Compressing objects: 100% (10/10), done.
53-
Writing objects: 100% (16/16), 258.30 KiB, done.
54-
Total 16 (delta 2), reused 16 (delta 2)
55-
72+
Counting objects: 3, done.
73+
Delta compression using up to 8 threads.
74+
Compressing objects: 100% (2/2), done.
75+
Writing objects: 100% (3/3), 283 bytes | 0 bytes/s, done.
76+
Total 3 (delta 1), reused 0 (delta 0)
77+
5678
-----> Receiving push
57-
-----> No runtime.txt provided; assuming python-2.7.3.
58-
-----> Preparing Python runtime (python-2.7.3)
79+
-----> No runtime.txt provided; assuming python-2.7.8.
80+
-----> Preparing Python runtime (python-2.7.8)
5981
-----> Installing Distribute (0.6.36)
6082
-----> Installing Pip (1.3.1)
6183
-----> Installing dependencies using Pip (1.3.1)
62-
Downloading/unpacking Flask==0.9 (from -r requirements.txt (line 1))
63-
...
64-
Successfully installed Flask Werkzeug Jinja2 markupsafe
84+
Downloading/unpacking Flask==0.10.1 (from -r requirements.txt (line 1))
85+
...
86+
Successfully installed Flask Werkzeug Jinja2 itsdangerous MarkupSafe
6587
Cleaning up...
6688
-----> Building image
67-
-----> Uploading image (25M)
68-
89+
-----> Uploading image (25.1 MB)
90+
6991
To ssh://[email protected]/repository.git
7092
* [new branch] master -> master
7193

0 commit comments

Comments
 (0)