Updates for changes in tutorial
This commit is contained in:
Родитель
721412d1bf
Коммит
2c4da4ccca
|
@ -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__)
|
|
@ -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
|
||||
|
|
12
runserver.py
12
runserver.py
|
@ -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)
|
Загрузка…
Ссылка в новой задаче