无法在flask web应用程序中的网页上加载图像 [英] Unable to load images on web pages in flask web application
问题描述
我的html代码在模板文件夹和图像在静态文件夹中
< img src =../ static / inner_banner5.jpgwidth =1400height =222>
我也在admin_login.html中使用了相同的功能
我的app.py代码是
__ author__ ='mullapudi'
from flask import Flask,request ,重定向,Blueprint,render_template,flash
blueprint =蓝图('app',__name__,url_prefix ='/ title')
@ blueprint.route('/', methods = ['GET','POST'])
def title():
#位于https://yourdomain.com/login
返回render_template('title.html')
lueprint.route('/ home /',methods = ['GET','POST'])
def home():
return redirect('/ title /')
@ blueprint.route('/ admin /',methods = ['GET','POST'])
def admin():
return render_template 'admin_login.html')
这里的问题是横幅在标题页中显示,超链接重定向到admin_login页面,但在admin_login页面,它不显示不要使用相对URL,请使用
$ b $
< img src ={{url_for('static',filename ='inner_banner5.jpg')}}width =1400height =222>
您的目录结构将会是
。
├──app.py
├──env
├──静态
│└──inner_banner5.jpg
└──模板
I am trying to develop an flask web application in which banners should be displayed on web pages,but when I run the app initially banners are displayed on title page,when I click on any hyperlink it should redirect to next page,but on that page banners are not displaying why?
my html codes are in templates folder and images are in static folder
i had used this in title.html
<img src="../static/inner_banner5.jpg" width="1400" height="222">
and i had also used the same in admin_login.html
my app.py code is
__author__ = 'mullapudi'
from flask import Flask,request,redirect,Blueprint,render_template,flash
blueprint = Blueprint('app', __name__, url_prefix='/title')
@blueprint.route('/', methods=['GET', 'POST'])
def title():
# Located at https://yourdomain.com/login
return render_template('title.html')
@blueprint.route('/home/', methods=['GET', 'POST'])
def home():
return redirect('/title/')
@blueprint.route('/admin/', methods=['GET', 'POST'])
def admin():
return render_template('admin_login.html')
the problem here is the banner is displaying in title page where it has a hyper link to redirect to the admin_login page but in admin_login page it was not displaying the banner why
Don't use relative URLs, use url_for
:
<img src="{{ url_for('static', filename='inner_banner5.jpg') }}" width="1400" height="222">
Your directory structure would then be
.
├── app.py
├── env
├── static
│ └── inner_banner5.jpg
└── templates
这篇关于无法在flask web应用程序中的网页上加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!