1
0
Форкнуть 0

Updates for changes in tutorial

This commit is contained in:
Kraig Brockschmidt 2018-05-25 11:07:18 -07:00
Родитель 721412d1bf
Коммит 2c4da4ccca
8 изменённых файлов: 47 добавлений и 35 удалений

7
.vscode/launch.json поставляемый
Просмотреть файл

@ -64,11 +64,12 @@
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "runserver.py",
"FLASK_ENV": "development"
"FLASK_APP": "HelloFlask/app.py"
},
"args": [
"run"
"run",
"--no-debugger",
"--no-reload" // Remove to auto-reload modified pages
]
},
{

Просмотреть файл

@ -1,4 +1,2 @@
from flask import Flask
app = Flask(__name__)
import HelloFlask.views
app = Flask(__name__)

5
HelloFlask/app.py Normal file
Просмотреть файл

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

Просмотреть файл

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="/static/site.css" />
<title>{{ title }}</title>
</head>
<body>
<span class="message">{{ message }}</span> It's {{ date }}.
</body>
</html>

Просмотреть файл

@ -1,4 +1,4 @@
{% extends "layout.html" %}
{% block content %}
<p><span class="message">{{ message }}</span> on {{ date }}</p>
<p>Home page for the Flask tutorial.</p>
{% endblock %}

Просмотреть файл

@ -1,22 +1,10 @@
from datetime import datetime
from flask import Flask
from flask import render_template
from HelloFlask import app
@app.route('/')
@app.route('/home')
def home():
now = datetime.now()
return render_template(
"home.html",
title ='Hello, Flask',
message = "Hello, Flask!",
date = now.strftime("%A, %d %B, %Y at %X")
)
@app.route('/api/data')
def get_data():
return app.send_static_file('data.json')
def home():
return render_template("home.html", title = "Home")
@app.route('/about')
def about():
@ -25,3 +13,19 @@ def about():
@app.route('/contact')
def contact():
return render_template("contact.html", title = "Contact us")
@app.route('/hello/<name>')
def hello_there(name):
from datetime import datetime
now = datetime.now()
return render_template(
"hello_there.html",
title ='Hello, Flask',
message = "Hello there, " + name + "!",
date = now.strftime("%A, %d %B, %Y at %X")
)
@app.route('/api/data')
def get_data():
return app.send_static_file('data.json')

Просмотреть файл

@ -1 +1,6 @@
flask
click==6.7
Flask==1.0.2
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
Werkzeug==0.14.1

Просмотреть файл

@ -1,12 +0,0 @@
from os import environ
from HelloFlask import app
if __name__ == '__main__':
HOST = environ.get('SERVER_HOST', 'localhost')
try:
PORT = int(environ.get('SERVER_PORT', '5555'))
except ValueError:
PORT = 5555
app.run(HOST, PORT)