python - Html 图标不会显示在我网站上的某些页面上,但会显示在其他页面上
问题描述
我的网站很小,但图标无法正常工作:这是代码:
base.html
<html>
<head>
<link rel="icon" href="static/icon.png" sizes="32x32">
<title>
{% block title %}{{title}}{% endblock %}
</title>
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div id="page_container">
{% block content %}
<div class="container-fluid" style="margin-top: 100px;">
{% with messages = get_flashed_messages() %}
{% if messages %}
{% for message in messages %}
<div class="alert alert-info" role="alert">{{message}}</div>
{% endfor %}
{% endif %}
{% endwith %}
{# application content needs to be provided in the app_content block #}
{% block app_content %}{% endblock %}
</div>
{% endblock %}
</div>
</body>
</html>
浏览器显示此模板上的图标:
about.html
{% extends "base.html" %}
{% block app_content %}
<div id="about_author_photo">
<img src="static/VVphoto.jpg" height="400px" width="270px">
</div>
{% endblock %}
但它不是这样的:
诗歌.html
{% extends "base.html" %}
{% block app_content %}
{% for poem in poems.items %}
{% include "_poem.html" %}
{% endfor %}
<div class="pagination-links">
{% for page in poems.iter_pages() %}
{% if page %}
{% if page != poems.page %}
<a href="{{ url_for('poems', page_num=page) }}">{{ page }}</a>
{% else %}
<span style="color: white;">({{ page }})</span>
{% endif %}
{% else %}
<span class=ellipsis style="color: white;">…</span>
{% endif %}
{% endfor %}
</div>
{% endblock %}
以下是他们两人的看法:
@app.route('/')
@app.route('/about')
def about():
return render_template('about.html', title='З Гумором Про Все На Світі')
@app.route('/poems/<int:page_num>')
def poems(page_num):
poems = Poem.query.paginate(per_page=5, page=page_num, error_out=True)
return render_template('poems.html', title='Вірші', poems=poems)
我尝试将图标添加到{% extends "base.html %}
行下的诗歌 tepmlate 但它不起作用
解决方案
图标 url 目前是相对的。你应该使用{{ url_for('static', filename='icon.png') }}
更多信息https://flask.palletsprojects.com/en/1.1.x/tutorial/static/
推荐阅读
- react-native - 如何在 Algolia Instant Search 中设置默认过滤器选项
- python - 简单游戏上的 Python 简单得分(点)系统
- python - 修复 PyTorch 神经网络中不正确的维度
- ios - OpenTok 会话卷更改不适用于 MPVolumeView
- php - PHP无法解压缩文件
- ruby-on-rails - 如何将文档附加到电子邮件 ActiveStorage 和 Cloudinary?
- python - 将新列表附加到双 for 循环中的键
- node.js - 如何在猫鼬中为产品添加多个过滤
- foreach - Jmeter ForEach 控制器未能按检索顺序将变量写入文件
- typescript - 自制方法装饰器擦除所有元数据,我该如何解决?