【发布时间】:2020-11-27 01:41:48
【问题描述】:
我的网络应用程序已启动并运行。
但是,我需要使用render_template 发布网站的输出,要让输出显示在文本输出中,我必须一次性传递所有内容。我使用列表执行此操作,但输出中的列表格式不正确。
我的网络应用:http://tomshoe02.pythonanywhere.com/scraper
示例输入:https://dtmwra1jsgyb0.cloudfront.net/groups/5e223506edae743046ecdaa2/matches
示例输出(屏幕截图):https://i.imgur.com/J2yOc3K.png
示例输出:['{{MatchSchedule|team1=UAlbany eSports|team2=Thomas Esports|team1score=2|team2score=0|winner=1|date=2020-02-07|time=13:00|timezone=PST|dst=yes|vod1=|stream=}}\n', '{{MatchSchedule|team1=King Tornado|team2=|team1score=|team2score=|winner=|date=2020-02-08|time=12:00|timezone=PST|dst=yes|vod1=|stream=}}\n', '{{Ma...
期望的输出:
{{MatchSchedule|team1=UAlbany eSports|team2=Thomas Esports|team1score=2|team2score=0|winner=1|date=2020-02-07|time=13:00|timezone=PST|dst=yes|vod1=|stream=}}
{{MatchSchedule|team1=King Tornado|team2=|team1score=|team2score=|winner=|date=2020-02-08|time=12:00|timezone=PST|dst=yes|vod1=|stream=}}
app.py
from flask import Flask, render_template
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField
import os, sys, subprocess, importlib
from stuff import jloader
directory = os.path.dirname(os.path.abspath(__file__))
app = Flask(__name__)
app.config['TEMPLATES_AUTO_RELOAD'] = True
app.config['SECRET_KEY'] = 'tomisgoated'
class BattlefyForm(FlaskForm):
matchhistory = StringField('Match History Link')
@app.route("/test")
def home():
return render_template("base.html")
@app.route("/", methods=["GET", "POST"])
@app.route("/lol", methods=["GET", "POST"])
@app.route("/scraper", methods=["GET", "POST"])
def scraper():
form = BattlefyForm()
if form.validate_on_submit():
url = form.matchhistory.data
result = jloader(url)
'''
#result = url
result = subprocess.check_output([sys.executable,
"{}/stuff.py".format(directory), url]).decode('iso-8859-1')
'''
return render_template("scraper.html", form=form, result=result)
return render_template("scraper.html", form=form)
@app.route('/base', methods=["GET"])
def base():
return render_template("base.html")
@app.template_filter('nl2br')
def nl2br(s):
return s.replace("\n", "<br />")
if __name__ == "__main__":
app.run(debug = True)
【问题讨论】: