Я могу распечатать свой вывод в Powershell, но хочу, чтобы текст отображался на веб-сайте, а не на Powershell.Отображение вывода 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: (Я объединил app.py с main.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 «Пробовал cgi, сеть, но не получилось. Как мне изменить код, чтобы получить текст на моем веб-сайте? Должен ли я добавить index.html?
http://flask.pocoo.org/docs/0.12/quickstart/#rendering-templates –
Что вы имеете в виду «А не было Не получается? – EJoshuaS