简体   繁体   English

图片不显示 bottle.py

[英]Picture not showing bottle.py

My picture isnt showing, I tryed copying code and that didnt work.我的图片没有显示,我尝试复制代码但没有用。 I want to be able to do this, what am i doing wrong?我希望能够做到这一点,我做错了什么?

my code我的代码

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)

in html1在 html1 中

  <img src="C:\Users\radbo\Desktop\discord bots\drago\chat\RUn\Servers\Turtle.png" width=290 length=100>

Use the template function to call your HTML so it is cached, then create a static path to your image file.使用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)

Then you can just do:然后你可以这样做:

<img src="\static\Turtle.png" width=290 length=100>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM