[英]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.