微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何将数据从 Python 文件传输到 HTML 文件?

如何解决如何将数据从 Python 文件传输到 HTML 文件?

我一直在尝试使用 Python 从 API 获取数据并将其显示到 HTML 页面中,但到目前为止我尝试的所有方法似乎都不起作用!我曾尝试使用 Flask 来显示 Python 变量,但服务器似乎无法正常工作!这是我的 Python 代码

ScratchDBtest.py

#imports all the required assets
import requests
import json
import sys
from time import sleep



#this fetches data from API
response = requests.get("https://scratchdb.lefty.one/v2/user/info/" + input("Enter Username: "))
#organises data
def jprint(object):
    #create a formatted string
    text = json.dumps(object,sort_keys = True,indent = 5)
    print(text)

#print(response.status_code)






answer = response.json()

#jprint(answer)

query_time = response.json()['query_time']
if not query_time < 10:
    followers = response.json()['followers']
    status = response.json()['status']
    username = response.json()['username']
    bio = response.json()['bio']
    country = response.json()['country']
    following = response.json()['following']
    result = username + " has " + str(followers) + " followers and has a scratcher status of " + status + ". The user lives in " + country
else:
    result = "An error occured. This account is not real or hasn't been logged into the database yet!"

#typewriting effect
for characters in result:
    sleep(0.01)
    sys.stdout.write(characters)
    sys.stdout.flush()

在这种情况下,我希望“结果”变量显示在 HTML 文件中。我还没有任何 HTML 代码,但文件名是 ScratchDBtest.html

如果有人能提供帮助,将不胜感激!谢谢!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。