Python中文
首页
教程
问答
标签
搜索
登录
注册
Django1.10模板在其Paren之外呈现嵌套的HTML标记
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我对Django模板的以下行为感到有点困惑,这使我无法成功地设计输出样式。你知道吗</p> <p>也就是说,我有以下模板:</p> <pre><code><article class="article {% if article.is_featured %} featured{% endif %} {% if not article.published %} unpublished{% endif %}"> {% if not detail_view %} <div class="post-preview"> <a href="{% namespace_url 'article-detail' article.slug namespace=namespace default='' %}"> <h2 class="post-title"> {% render_model article "title" "" "" "striptags" %} </h2> {% if article.lead_in %} <h3 class="post-subtitle"> {% if not detail_view %} {% render_model article "lead_in" "" "" "truncatewords:'20'|striptags" %} {% else %} {% render_model article "lead_in" "" "" "striptags" %} {% endif %} </h3> {% endif %} </a> <p class="post-meta" style="margin-bottom: 0;"> Posted by {% include "aldryn_newsblog/includes/author.html" with author=article.author %} on {{ article.publishing_date|date:"F d, Y" }} </p> <p class="post-meta" style="margin: 0"> <h4 style="display:inline-flex">Categories:</h4> {% for category in article.categories.all %} <a href="/articles/category/{{category.name|lower}}">{{ category.name }} {% if not forloop.last %}, {% endif %}</a> {% endfor %} </p> <p class="post-meta" style="margin: 0"> <h4 style="display:inline-flex">Tags:</h4> {% for tag in article.tag %} <a href="/articles/category/{{tag.name|lower}}">{{ tag.name }} {% if not forloop.last %}, {% endif %}</a> {% endfor %} </p> </div> <hr> {% endif %} {% if detail_view %} <!-- <h3>Testing template! (from article with detail_view=True)</h3> --> {% render_placeholder article.content language placeholder_language %} {% endif %} </article> </code></pre> <p>此模板的输出大致如下:</p> <pre><code><article class="article"> <div class="post-preview"> <a href="/articles/third-post/"> <h2 class="post-title"> Third Post </h2> <h3 class="post-subtitle"> Third post lead-in text. </h3> </a> <p class="post-meta" style="margin-bottom: 0;"> Posted by <a href=""> </a> on September 19, 2017 </p> <p class="post-meta" style="margin: 0"> <h4 style="display:inline-flex">Categories:</h4> <a href="/articles/category/programming">Programming </a> </p> <p class="post-meta" style="margin: 0"> <h4 style="display:inline-flex">Tags:</h4> </p> </div> <hr> </article> </code></pre> <p>尽管源HTML看起来是正确的,但浏览器将其视为下图所示。你知道吗</p> <p><a href="https://i.stack.imgur.com/DzGuM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DzGuM.png" alt="As you can see, the H4 tag and others are taken outside the <p> tag."/></a></p> <p>我错过了什么?模板是否不正确?或者这是我观察到的虫子?我在Safari和Firefox上试过这个。结果是一样的。你知道吗</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>不,那只是浏览器开发工具试图理解无效的HTML。你知道吗</p> <p><code>h</code>元素不能进入<code>p</code>元素内部。你知道吗</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
jupyter运行一个旧的pytorch版本
9 回答
Jupyter运行不同版本的卸载库?
6 回答
Jupyter运行指定的键盘快捷键
8 回答
Jupyter通过.local文件“逃逸”virtualenv。我该如何缓解这种情况?
2 回答
Jupyter重新加载自定义样式
10 回答
Jupyter错误:“没有名为Jupyter_core.paths的模块”
9 回答
jupyter错误:无法在随机林中将决策树视为png
5 回答
Jupyter错误'内核似乎已经死亡,它将自动重新启动'为一个给定的代码块
2 回答
Jupyter错误地用阿拉伯语和字母数字元素显示Python列表
2 回答
Jupyter隐藏数据帧索引,但保留原始样式
4 回答
Jupyter集线器:启动器中出现致命错误。。。系统找不到指定的文件
10 回答
Jupyther中相同值的相同哈希,但导出到Bigquery时不相同
3 回答
Jupy上Python的读/写访问问题
5 回答
jupy上没有模块cv
7 回答
Jupy上的排序错误
4 回答
Jupy中bqplot图形的紧凑布局
4 回答
Jupy中matplotlib plot的连续更新
4 回答
Jupy中Numpy函数的文档
4 回答
Jupy中Pandas的自动完成问题
6 回答
jupy中Qt后端的Matplotlib动画
2 回答