【问题标题】:Picture not showing bottle.py图片不显示瓶子.py
【发布时间】:2022-03-16 06:41:38
【问题描述】:

我的图片没有显示,我尝试复制代码,但没有成功。我希望能够做到这一点,我做错了什么?

我的代码

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>

【问题讨论】:

    标签: python html bottle


    【解决方案1】:

    使用template 函数调用您的HTML,使其被缓存,然后为您的图像文件创建一个静态路径。

    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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-19
      • 2017-12-16
      • 1970-01-01
      • 2015-07-15
      • 2013-12-21
      相关资源
      最近更新 更多