html表格中的新行

法比奥

我的模特:

class Affiliation(models.Model):
    name = models.CharField(max_length=32)
    slug = models.SlugField(unique=True)
    descrizione = models.CharField(max_length=500, blank=True, null=True)

class Reg_Affiliation(models.Model):
    reg = ...
    affiliazione = models.ForeignKey(Affiliation, null=True, 
        on_delete=models.CASCADE, related_name='affiliation_conoscenza')

我的descrizione领域(例如):

descrizione = 'line1 <br> line2'

编辑:添加了有关此字段的内容,请参见下文/ edit

我也尝试过:

descrizione = "line1 '<br>' line2"
descrizione = 'line1 "<br>" line2'
descrizione = 'line1 \n line2'
descrizione = 'line1 \r\n line2'

我的模板:

<div class="panel panel-default">
<table class="table table-striped table table-bordered table table-hover table table-condensed">
  <thead>
    <tr>
      <th>Nome</th>
      <th>Descrizione</th>
    </tr>
  </thead>

  <tbody>
    {% for aff in lista %}
      <tr>
        <td>
            <b>{{ aff.affiliazione }}</b>
        </td>
        <td>
            {{ aff.affiliazione.descrizione }}
        </td>
      </tr>
    {% endfor %}
  </tbody>
</table>

我预计:

line1

line2

在表的同一字段中,而是获取:

line1 <br> line2

我的views

@login_required
def affiliation_list(request):
    lista_a=[]
    for a in Affiliation.objects.all():
        ra=Reg_Affiliation(affiliazione=a, 
                conoscenza=c, 
                rapporto=r)
            lista_a.append(ra)
        context_dict['lista'] = lista_a
    return render(request, 'core/affiliation_list.html', context_dict)

我正在使用Bootstrap,Firefox,Windows7

感谢您的帮助

编辑:

也许这与我添加descrizione字段的方式有所不同,所以:

我的populate剧本:

import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sitoposs.settings')

import django
django.setup()

def populate():

    affiliation1 = add_affiliation('name affiliation1', '''long line1 <br> long line2''')
    affiliation2 = 
    ...

def add_affiliation(name, descrizione):
    a = Affiliation.objects.get_or_create(name=name)[0]
    a.descrizione=descrizione
    a.save()
    return a

if __name__ == '__main__':
    populate()

在我的数据库中,我读到

long line1 <br> long line2

在源页面中(在浏览器上右键单击页面,查看源页面或类似内容,我不使用英语版本)我读到:long line1 <br> long line2

在填充脚本中,我也尝试过:

affiliation1 = add_affiliation('name affiliation1', 'long line1 and <br> long line2 in the same line, so unreadable')
米努丁·艾哈迈德·拉纳(Minuddin Ahmed Rana)

descrizione = models.TextField(max_length=500, blank=True, null=True)代替descrizione = models.CharField(max_length=500, blank=True, null=True)

{% autoescape off %}{{ aff.affiliazione.descrizione }}{% endautoescape %}代替{{ aff.affiliazione.descrizione }}

通常django会转义所有html标签并将其呈现为原始文本,以呈现实际的html,您也可以使用 {{ aff.affiliazione.descrizione|safe }}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

过滤HTML中的表格行

来自分类Dev

如何在表格单元格中创建新行

来自分类Dev

为OOO Calc电子表格中的每一行创建新的txt / html文件

来自分类Dev

html表格中的新行

来自分类Dev

在HTML表格中每页显示N行

来自分类Dev

Excel表格顶部的新行

来自分类Dev

在Google表格单元格中删除HTML(并添加新行)

来自分类Dev

如何在HTML表格中添加新行

来自分类Dev

在react / html中渲染新行(\ n)

来自分类Dev

如何在HTML中添加新行?

来自分类Dev

HTML中的新行

来自分类Dev

从javascript中的HTML表格中删除一行

来自分类Dev

HTML中表格中的表格

来自分类Dev

过滤HTML中的表格行

来自分类Dev

HTML中的新行

来自分类Dev

jscrollpane中表格中的新数据行不滚动吗?

来自分类Dev

html中水平表格行上的文本

来自分类Dev

为OOO Calc电子表格中的每一行创建新的txt / html文件

来自分类Dev

HTML表格内容:如果行很长,如何在新行中显示部分内容

来自分类Dev

显示表格-CSS,使成对的表格单元格出现在新行中

来自分类Dev

表格中的新表格行

来自分类Dev

HTML隐藏表格行

来自分类Dev

PhpStorm HTML替换中的新行

来自分类Dev

在 HTML 中对齐表格行

来自分类Dev

HTML 表格自动开始将行拆分为新列

来自分类Dev

HTML 表格中 2 行之间的间距

来自分类Dev

删除 HTML 表格中的行

来自分类Dev

HTML 表格行创建

来自分类Dev

通过在 Google 表格中添加新行来复制列