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问题
使用登录请求.post导致“错误405不允许”
1 回答
使用登录进行Python web抓取
1 回答
使用登录进行抓取
9 回答
使用登录页面从网站抓取数据
2 回答
使用白色圆圈背景使图像更平滑
3 回答
使用百分位数删除Pandas数据帧中的异常值
10 回答
使用百分号进行Python字典操作
7 回答
使用百分比delimi的Python字符串模板
6 回答
使用百分比分割Numpy ndarray最有效的方法是什么?
5 回答
使用百分比分配和修改变量(计算)
1 回答
使用百分比单位绘制数据
3 回答
使用百分比在单个采购订单中组合不同的订单类型
8 回答
使用百分比将数据帧的子集与完整数据帧进行比较
5 回答
使用百分比形式的BBOX选项,而不是绝对像素PyScreenShot Python
2 回答
使用百分比登录列nam更新表
1 回答
使用百分比登录操作系统或者os.popen公司
3 回答
使用百分比计算:十进制还是可读?
3 回答
使用的dataset和dataloader加载数据时出错torch.utils.data公司. TypeError:类型为“type”的对象没有len()
1 回答
使用的Json无效json.dump文件在Python3
6 回答
使用的overwrite方法\r在python 3[PyCharm]中不起作用
4 回答