Django HTML导入文本的最大长度 [英] Django HTML max length of imported text

查看:38
本文介绍了Django HTML导入文本的最大长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在django上的一个项目中进行尝试,并试图尽量减少显示各种主题条目的页面上显示的文本量.想法是只给出前200个字符,然后他们可以在另一页中打开它以读取整个条目.

I am working on a project in django and am trying to minimize the amount of text displayed on a page showing entries for various topics. The idea is to just give the first 200 characters and then they can open it in another page to read the whole entry.

下面是html页面的代码...

Below is the code for the html page...

{% extends "AARs/base.html" %}

{% block header %}
  <h2>{{ topic }}</h2>
{% endblock header %}

{% block content %}
  <p>
    <a href="{% url 'AARs:new_action' topic.id %}">Add new action</a>
  </p>

  {% for action in actions %}
    <div class="panel panel-default">
      <div class="panel-heading">
        <small>
          {{ action.date_added|date:'M d, Y H:i' }}
        </small>
        <small>  <a href="{% url 'AARs:edit_action' action.id %}">Read or Edit Action</a></small>
      </div>
      <div class="panel-body">
        <small>
          <input type="text" name="action" maxlength="10">
            {{ action.text|linebreaks }}
        </small>
      </div>
    </div>
  {% empty %}
    No actions have been added yet.
  {% endfor %}

{% endblock content %}

我曾尝试在我认为可能可行的各个位置插入maxlength ="200",但无济于事.

I have tried inserting maxlength="200" in various places that I thought might work, but to no avail.

很明显,我是新手.我做的事情超出了我的水平,我感到很兴奋.任何帮助表示赞赏.

Obviously, I am a newbie. Am excited to be doing stuff beyond my level. Any help is appreciated.

推荐答案

您可以使用模板标签

https://docs.djangoproject.com/en/2.1/ref/templates/builtins/#truncatechars

{{ action.text|truncatechars:200 }}

这篇关于Django HTML导入文本的最大长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆