Line & paragraph chopping

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
from django.template import Library

register = Library()

@register.filter
def paragraphs(var, arg):
    paras = var.replace("\r\n", "\n").split("\n\n")
    return "\n\n".join(paras[:int(arg)])

@register.filter
def lines(var, arg):
    lines = var.replace("\r\n", "\n").split("\n")
    return "\n".join(lines[:int(arg)])

More like this

  1. Serving null files by ludvig.ericson 6 years, 2 months ago
  2. check if form has changed (deprecated) by guettli 5 years, 2 months ago
  3. Debug-only static serving by ludvig.ericson 5 years, 4 months ago
  4. Improved Accept header middleware by ludvig.ericson 4 years, 8 months ago
  5. Remove old fields on dumpdata generated json by facundo_olano 1 year, 7 months ago

Comments

(Forgotten your password?)