Read more link

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#myapp/templatetags/blog_filters.py

from django import template
register = template.Library()
import settings

@register.filter('read_more')
def read_more(body, absolute_url):
	if '<!--more-->' in body:
		return body[:body.find('<!--more-->')]+'<a href="'+str(absolute_url)+'">'+str(settings.READ_MORE_TEXT)+'</a>'
	else:
		return body

More like this

  1. Unobtrusive comment moderation by ubernostrum 7 years, 1 month ago
  2. Find all links in a value and display them separatley by jcroft 7 years, 1 month ago
  3. Hyperlink list filter by lifefloatsby 6 years, 3 months ago
  4. Template filter to convert timecodes into links by justin_h 4 years, 7 months ago
  5. Automatically slugify slug fields in your models by Aliquip 7 years, 1 month ago

Comments

svetlyak (on September 4, 2008):

I'll rewrite this as:

def read_more(body, absolute_url):
    pos = body.find('<!--more-->')
    if pos == -1:
        return body
    else:
        return '<a href="%s">%s</a>' % (body[:pos], settings.READ_MORE_TEXT))

#

(Forgotten your password?)