Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 222135c

Browse files
author
Kraig Brockschmidt
committedMay 14, 2018
Initial commit of sample files
1 parent 6f08382 commit 222135c

File tree

12 files changed

+245
-0
lines changed

12 files changed

+245
-0
lines changed
 

‎.vscode/launch.json

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Python: runserver.py",
9+
"type": "python",
10+
"request": "launch",
11+
"program": "${workspaceFolder}/runserver.py",
12+
},
13+
{
14+
"name": "Python: Current File",
15+
"type": "python",
16+
"request": "launch",
17+
"program": "${file}",
18+
"env": {
19+
"FLASK_ENV": "development"
20+
}
21+
},
22+
{
23+
"name": "Python: Attach",
24+
"type": "python",
25+
"request": "attach",
26+
"localRoot": "${workspaceFolder}",
27+
"remoteRoot": "${workspaceFolder}",
28+
"port": 3000,
29+
"secret": "my_secret",
30+
"host": "localhost"
31+
},
32+
{
33+
"name": "Python: Terminal (integrated)",
34+
"type": "python",
35+
"request": "launch",
36+
"program": "${file}",
37+
"console": "integratedTerminal"
38+
},
39+
{
40+
"name": "Python: Terminal (external)",
41+
"type": "python",
42+
"request": "launch",
43+
"program": "${file}",
44+
"console": "externalTerminal"
45+
},
46+
{
47+
"name": "Python: Django",
48+
"type": "python",
49+
"request": "launch",
50+
"program": "${workspaceFolder}/manage.py",
51+
"args": [
52+
"runserver",
53+
"--noreload",
54+
"--nothreading"
55+
],
56+
"debugOptions": [
57+
"RedirectOutput",
58+
"Django"
59+
]
60+
},
61+
{
62+
"name": "Python: Flask (0.11.x or later)",
63+
"type": "python",
64+
"request": "launch",
65+
"module": "flask",
66+
"env": {
67+
"FLASK_APP": "runserver.py",
68+
"FLASK_ENV": "development"
69+
},
70+
"args": [
71+
"run"
72+
]
73+
},
74+
{
75+
"name": "Python: Module",
76+
"type": "python",
77+
"request": "launch",
78+
"module": "module.name"
79+
},
80+
{
81+
"name": "Python: Pyramid",
82+
"type": "python",
83+
"request": "launch",
84+
"args": [
85+
"${workspaceFolder}/development.ini"
86+
],
87+
"debugOptions": [
88+
"RedirectOutput",
89+
"Pyramid"
90+
]
91+
},
92+
{
93+
"name": "Python: Watson",
94+
"type": "python",
95+
"request": "launch",
96+
"program": "${workspaceFolder}/console.py",
97+
"args": [
98+
"dev",
99+
"runserver",
100+
"--noreload=True"
101+
]
102+
},
103+
{
104+
"name": "Python: All debug Options",
105+
"type": "python",
106+
"request": "launch",
107+
"pythonPath": "${config:python.pythonPath}",
108+
"program": "${file}",
109+
"module": "module.name",
110+
"env": {
111+
"VAR1": "1",
112+
"VAR2": "2"
113+
},
114+
"envFile": "${workspaceFolder}/.env",
115+
"args": [
116+
"arg1",
117+
"arg2"
118+
],
119+
"debugOptions": [
120+
"RedirectOutput"
121+
]
122+
}
123+
]
124+
}

‎.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"python.pythonPath": "${workspaceFolder}\\env\\Scripts\\python.exe"
3+
}

‎HelloFlask/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from flask import Flask
2+
app = Flask(__name__)
3+
4+
import HelloFlask.views

‎HelloFlask/static/data.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"01": {
3+
"note" : "Data is very simple because we're demonstrating only the mechanism."
4+
}
5+
}

‎HelloFlask/static/site.css

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
.message {
2+
font-weight: 600;
3+
color: blue;
4+
}
5+
6+
.navbar {
7+
background-color: lightslategray;
8+
font-size: 1em;
9+
font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
10+
color: white;
11+
padding: 8px 5px 8px 5px;
12+
}
13+
14+
.navbar a {
15+
text-decoration: none;
16+
color: inherit;
17+
}
18+
19+
.navbar-brand {
20+
font-size: 1.2em;
21+
font-weight: 600;
22+
}
23+
24+
.navbar-item {
25+
font-variant: small-caps;
26+
margin-left: 30px;
27+
}
28+
29+
.body-content {
30+
padding: 5px;
31+
font-family:'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
32+
}

‎HelloFlask/templates/about.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{% extends "layout.html" %}
2+
{% block content %}
3+
<p>About page for the Flask tutorial.</p>
4+
{% endblock %}

‎HelloFlask/templates/contact.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{% extends "layout.html" %}
2+
{% block content %}
3+
<p>Contact page for the Flask tutorial.</p>
4+
{% endblock %}

‎HelloFlask/templates/home.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{% extends "layout.html" %}
2+
{% block content %}
3+
<p><span class="message">{{ message }}</span> on {{ date }}</p>
4+
{% endblock %}

‎HelloFlask/templates/layout.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>{{ title }}</title>
6+
<link rel="stylesheet" type="text/css" href="/static/site.css" />
7+
</head>
8+
9+
<body>
10+
<div class="navbar">
11+
<a href="{{ url_for('home') }}" class="navbar-brand">Home</a>
12+
<a href="{{ url_for('about') }}" class="navbar-item">About</a>
13+
<a href="{{ url_for('contact') }}" class="navbar-item">Contact</a>
14+
</div>
15+
16+
<div class="body-content">
17+
{% block content %}
18+
{% endblock %}
19+
<hr/>
20+
<footer>
21+
<p>&copy; 2018</p>
22+
</footer>
23+
</div>
24+
</body>
25+
</html>

‎HelloFlask/views.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from datetime import datetime
2+
from flask import render_template
3+
from HelloFlask import app
4+
5+
@app.route('/')
6+
@app.route('/home')
7+
def home():
8+
now = datetime.now()
9+
10+
return render_template(
11+
"home.html",
12+
title ='Hello, Flask',
13+
message = "Hello, Flask!",
14+
date = now.strftime("%A, %d %B, %Y at %X")
15+
)
16+
17+
@app.route('/api/data')
18+
def get_data():
19+
return app.send_static_file('data.json')
20+
21+
@app.route('/about')
22+
def about():
23+
return render_template("about.html", title = "About us")
24+
25+
@app.route('/contact')
26+
def contact():
27+
return render_template("contact.html", title = "Contact us")

‎requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Flask<1

‎runserver.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import os
2+
from HelloFlask import app
3+
4+
if __name__ == '__main__':
5+
HOST = os.environ.get('SERVER_HOST', 'localhost')
6+
7+
try:
8+
PORT = int(os.environ.get('SERVER_PORT', '5555'))
9+
except ValueError:
10+
PORT = 5555
11+
12+
app.run(HOST, PORT)

0 commit comments

Comments
 (0)
Please sign in to comment.