0
Powershellで出力を印刷できますが、PowerShellではなく、Webサイトにテキストを表示します。ここで ウェブサイトへのpython出力の表示
は私のindex.htmlです:<!DOCTYPE html>
<html>
<head>
<title>Fluxus Generator</title>
</head>
<body bgColor="peachpuff">
<center><h1>Fluxus Generator</h1><center>
<center><img src="card.png" alt="Card" /></center>
<font face= "Calibri" size="7" color = "purple">
<center><p><a href="/">Another Card</a></p></center>
</body>
</html>
、ここapp.pyです:
from bs4 import BeautifulSoup
import requests
import random
from flask import Flask
from flask import render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
def generate_word():
"""Generate a list of words and shuffle them"""
words = list()
req = requests.get('https://en.wikipedia.org/wiki/List_of_plain_English_words_and_phrases')
html_source = req.text
soup = BeautifulSoup(html_source, "html.parser")
for source in soup.find_all('a', { "class" : "extiw" }):
word = source.find(text = True)
try:
word = str(word)
words.append(word)
except:
pass
random.shuffle(words)
return words
def generate_instruction(words):
"""Build an instruction from the word lists"""
instruction_struct = [
'I', words[0], words[1], words[8], 'the',
words[2], words[5], 'with',
words[4], words[7]
]
instruction = ' '.join(instruction_struct)
print instruction
words = generate_word()
generate_instruction(words)
if __name__ == '__main__':
app.run()
I(私は別に動作しませんでしたので、main.pyでapp.pyユナイテッド) cgi、webを試しましたがうまくいきませんでした。 私のウェブサイトにテキストが表示されるようにコードを変更する必要はありますか? index.htmlに追加する必要がありますか?
http://flask.pocoo.org/docs/0.12/quickstart/#rendering-templates –
あなたが「のdidnをどういう意味ですか運動しない? – EJoshuaS