当前位置:   article > 正文

Python Flask 搭建个人网站_python搭建个人网站

python搭建个人网站

介绍

Hello Kuko 是使用Python+Flask这样的组合搭建的网站,虽然其中的功能根本没有。

项目已开源到github:kuko


app.py

  1. import io
  2. import json
  3. import os
  4. import random
  5. from flask import Flask
  6. from flask import url_for
  7. from flask import request
  8. from flask import jsonify
  9. from flask import render_template
  10. from flask import send_file
  11. import requests
  12. from rembg import remove
  13. from PIL import Image
  14. from fileid import fileid
  15. import GetPixivImage
  16. import SearchMusic
  17. app = Flask(__name__)
  18. @app.route("/")
  19. def index():
  20. __files = []
  21. for paths, dirs, files in os.walk(f"./static/index/PYDOME_TYPE/images/slides"):
  22. for file in files:
  23. __files.append(paths+f"/{file}")
  24. return render_template("index.html", BgImageFile=__files)
  25. @app.route("/10_12")
  26. def birthday10_12():
  27. return render_template("10_12.html")
  28. @app.errorhandler(404)
  29. def Error_404(error):
  30. return render_template("404.html"), 404
  31. @app.route("/Mili_Wallpaper")
  32. def Mili_Wallpaper():
  33. return render_template("Mili_Wallpaper.html")
  34. @app.route("/Mili_Wallpaper/list")
  35. def Mili_Wallpaper_List():
  36. return render_template("list.html")
  37. @app.route("/and")
  38. def Mili_Wallpaper_AndHtml():
  39. return render_template("and.html")
  40. @app.route("/API/MiliWallpaper/Mili_Wallpaper_Version")
  41. def Mili_Wallpaper_Version():
  42. return render_template("MiliWallpaperVersion.html")
  43. def GetAPIAudio(DIR):
  44. Audio = []
  45. for paths, dirs, files in os.walk(DIR):
  46. for file in files:
  47. Audio.append(f"{paths}/{file}")
  48. return Audio
  49. @app.route("/API/dls")
  50. def Dls():
  51. return send_file(random.choice(GetAPIAudio("./static/dls/audio")))
  52. @app.route("/API/hutao")
  53. def hutao():
  54. return send_file(random.choice(GetAPIAudio("./static/hutao/audio")))
  55. @app.route("/API/maren")
  56. def maren():
  57. return send_file(random.choice(GetAPIAudio("./static/maren/audio")))
  58. @app.route("/API/share")
  59. def ShareFile():
  60. FileName = request.args.get("filename")
  61. if FileName:
  62. try:
  63. return send_file(f"./static/share/{FileName}")
  64. except FileNotFoundError:
  65. return "FileName Error"
  66. else:
  67. return "Not FileName"
  68. @app.route("/API/PixivImage")
  69. def PixivImage():
  70. return {
  71. "url": GetPixivImage.GetImageUrl(random.choice(GetPixivImage.GetRanking()))
  72. }
  73. @app.route("/rembg")
  74. def Rembg():
  75. FileUrl = request.args.get("file")
  76. RandomFileName = fileid.Newid(10).newfileid()
  77. if FileUrl:
  78. GET = requests.get(FileUrl)
  79. if GET.status_code == 200:
  80. remove(Image.open(io.BytesIO(GET.content))).save(f"./static/rembg/log/{RandomFileName}.png")
  81. return send_file(f"./static/rembg/log/{RandomFileName}.png")
  82. else:
  83. return jsonify({"code": "File Url Eorror"})
  84. else:
  85. return jsonify({"code": "Not File Url"})
  86. @app.route("/RziL")
  87. def RziL():
  88. RaedSlidesJson = json.loads(open("./static/index/PYDOME_TYPE/images/slides/slides.json", "r", encoding="utf-8").read())
  89. return render_template(
  90. "RziL.html",
  91. bg=random.choice([i for i in RaedSlidesJson.values()]),
  92. RandomColor=random.choice(
  93. [
  94. 'rad',
  95. 'yellow',
  96. 'blue',
  97. "black",
  98. "silver",
  99. "gray",
  100. "white",
  101. "maroon",
  102. "purple",
  103. "fuchsia",
  104. "green",
  105. "lime",
  106. "olive",
  107. "navy",
  108. "blue",
  109. "teal",
  110. "aqua"
  111. ]
  112. )
  113. )
  114. @app.route("/RziLSearch")
  115. def RziLSearch():
  116. MusicName = request.args.get("MusicName")
  117. if MusicName:
  118. return render_template(
  119. "RziLSearch.html",
  120. MusicData=SearchMusic.Search(MusicName).SearchAll()
  121. )
  122. else:
  123. return "Not FileName"
  124. @app.route("/LSP")
  125. def LSP():
  126. return render_template("LSP.html")
  127. if __name__ == '__main__':
  128. app.run(
  129. host='0.0.0.0',
  130. port=80,
  131. debug=True,
  132. )

程序会占用服务器中的80端口,你可以更改port的值来更换端口。


/rembg

"[http/https]://0.0.0.0/rembg?file=[fileurl]" 是python 开源项目rembg 的一个是调用接口,使用rembg库来实现图片人物提取的功能。file参数代表网络上的图片文件。


项目开源地址:GitHub - PYmili/kuko: 使用flask框架 制作的博客网页

联系:qq群:706128290

祝大家除夕快乐!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/黑客灵魂/article/detail/765533
推荐阅读
相关标签
  

闽ICP备14008679号