Skip to content

Commit 2c4da4c

Browse files
author
Kraig Brockschmidt
committed
Updates for changes in tutorial
1 parent 721412d commit 2c4da4c

File tree

8 files changed

+47
-35
lines changed

8 files changed

+47
-35
lines changed

.vscode/launch.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,12 @@
6464
"request": "launch",
6565
"module": "flask",
6666
"env": {
67-
"FLASK_APP": "runserver.py",
68-
"FLASK_ENV": "development"
67+
"FLASK_APP": "HelloFlask/app.py"
6968
},
7069
"args": [
71-
"run"
70+
"run",
71+
"--no-debugger",
72+
"--no-reload" // Remove to auto-reload modified pages
7273
]
7374
},
7475
{

HelloFlask/__init__.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
from flask import Flask
2-
app = Flask(__name__)
3-
4-
import HelloFlask.views
2+
app = Flask(__name__)

HelloFlask/app.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from HelloFlask import app
2+
from HelloFlask import views
3+
4+
# Time-saver: output a URL to the VS Code terminal so you can easily Ctrl+click to open a browser
5+
# print('http://127.0.0.1:5000/hello/VSCode')

HelloFlask/templates/hello_there.html

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="stylesheet" type="text/css" href="/static/site.css" />
6+
<title>{{ title }}</title>
7+
</head>
8+
<body>
9+
<span class="message">{{ message }}</span> It's {{ date }}.
10+
</body>
11+
</html>

HelloFlask/templates/home.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{% extends "layout.html" %}
22
{% block content %}
3-
<p><span class="message">{{ message }}</span> on {{ date }}</p>
3+
<p>Home page for the Flask tutorial.</p>
44
{% endblock %}

HelloFlask/views.py

+19-15
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
1-
from datetime import datetime
1+
from flask import Flask
22
from flask import render_template
33
from HelloFlask import app
44

55
@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')
6+
def home():
7+
return render_template("home.html", title = "Home")
208

219
@app.route('/about')
2210
def about():
@@ -25,3 +13,19 @@ def about():
2513
@app.route('/contact')
2614
def contact():
2715
return render_template("contact.html", title = "Contact us")
16+
17+
@app.route('/hello/<name>')
18+
def hello_there(name):
19+
from datetime import datetime
20+
now = datetime.now()
21+
22+
return render_template(
23+
"hello_there.html",
24+
title ='Hello, Flask',
25+
message = "Hello there, " + name + "!",
26+
date = now.strftime("%A, %d %B, %Y at %X")
27+
)
28+
29+
@app.route('/api/data')
30+
def get_data():
31+
return app.send_static_file('data.json')

requirements.txt

+6-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
flask
1+
click==6.7
2+
Flask==1.0.2
3+
itsdangerous==0.24
4+
Jinja2==2.10
5+
MarkupSafe==1.0
6+
Werkzeug==0.14.1

runserver.py

-12
This file was deleted.

0 commit comments

Comments
 (0)