[英]Picture not showing bottle.py
我的图片没有显示,我尝试复制代码但没有用。 我希望能够做到这一点,我做错了什么?
我的代码
from bottle import route, run,Response,template
from bottle import *
import socket
temp=open("ht","r")
html1=temp.read()
temp=open("html2","r")
html2=temp.read()
@route("/")
def route1():
return html1
run(host=socket.gethostbyname(socket.gethostname()), port=8080, debug=True)
在 html1 中
<img src="C:\Users\radbo\Desktop\discord bots\drago\chat\RUn\Servers\Turtle.png" width=290 length=100>
使用template
function 调用您的 HTML 以便它被缓存,然后创建一个 static 路径到您的图像文件。
from bottle import route, run, response, request, template, static_file, get
@route("/")
def route1():
#this should be your full filename, like index.html
return template('ht')
@get('/static/<filepath:path>')
def _shared(filepath):
return static_file(filepath, 'C:\Users\radbo\Desktop\discord bots\drago\chat\RUn\Servers' )
run(host='127.0.0.1', port=8080, debug=True)
然后你可以这样做:
<img src="\static\Turtle.png" width=290 length=100>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.