今天來對後端那個主要的app.py動手動腳吧
from flask import Flask, redirect, render_template, request
from flask_bootstrap import Bootstrap
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import DataRequired
import requests
app = Flask(__name__)
bootstrap = Bootstrap(app) # 傳遞到網頁的bootstrap
app.config['SECRET_KEY'] = 'd8e10bb4-f0da-11ea-ab7f-acde48001122' # 為預防 CSRF攻擊預先設置一組金鑰
class NameForm(FlaskForm):
name = StringField('我的工作清單', validators=[DataRequired()]) # 但
submit = SubmitField('Submit')
@app.route('/',methods=['GET', 'POST'])
def index():
dom = requests.get(
"https://opendata.cwb.gov.tw/api/v1/rest/datastore/O-A0003-001?Authorization=CWB-api-token&format=JSON"
).json()
location = dom['records']['location'][11]['parameter'][0]['parameterValue']
temp = dom['records']['location'][11]['weatherElement'][3]['elementValue']
Name = dom['records']['location'][11]['weatherElement'][3]['elementName']
print(location + temp + ":" + Name)
form = NameForm()
if form.validate_on_submit():
name = form.name.data
form.name.data = ""
return render_template('index.html', location=location, temp=temp, Name=Name, form=form, name=form.name)
Form 送出去資料 ,Response 怎麼沒東西啦
Day. 15 靜下心來,寫程式那有不碰到BUG的道理呢?