Heim  >  Artikel  >  Web-Frontend  >  Python怎么在web应用中添加本地的图片资源?_html/css_WEB-ITnose

Python怎么在web应用中添加本地的图片资源?_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:22:401828Durchsuche

主程序的部分代码:

app = Flask(__name__)@app.route('/', methods=['GET', 'POST'])def home():    return render_template('home.html')

<!DOCTYPE HTML><html><head>  <title>Welcome, {{ username }}</title></head><body>  <img  src = 'E:\code\static\test.PNG' alt="Python怎么在web应用中添加本地的图片资源?_html/css_WEB-ITnose" >#这里的url无效  <p>Welcome, {{ username }}!</p></body></html>


我直接运行home.html是可以显示图片的的

但是一旦通过python返回的html模板就不能显示图片了,就像这样:

两个网页的html源码在图片部分是一样的,但是通过python返回给浏览器的html就不能显示图片,我猜测是因为浏览器不能识别本地的url?于是我又搜了半天,加入了什么static_path,又试了url_for都不管用,今天第一次接触web开发,卡在这个地方3小时了,由于很多知识都不懂,希望大神解释一下。。


回复讨论(解决方案)

求解答啊....

Python怎么在web应用中添加本地的图片资源?_html/css_WEB-ITnose#这里的url无效
不能写成物理路径的,别人看不了的。你可以
Python怎么在web应用中添加本地的图片资源?_html/css_WEB-ITnose写成相对路径
或者
Python怎么在web应用中添加本地的图片资源?_html/css_WEB-ITnose写成绝对路径

Python怎么在web应用中添加本地的图片资源?_html/css_WEB-ITnose#这里的url无效
不能写成物理路径的,别人看不了的。你可以
Python怎么在web应用中添加本地的图片资源?_html/css_WEB-ITnose写成相对路径
或者
Python怎么在web应用中添加本地的图片资源?_html/css_WEB-ITnose写成绝对路径



非常感谢,我猜测到是这个问题,但是不知道怎么让别人识别....原来有相对路径这个东西非常感谢,这四个关键字解决了我的疑惑.
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn