I couldn't find any code for a blog-style "Read more after the jump," so I made a custom filter. It will look for <!--more--> for the jump, like in Wordpress.
In settings.py set READ_MORE_TEXT to what you want the text of the link to be.
READ_MORE_TEXT = 'Read more after the jump.'
When you call the filter in your template, pass it the absolute link of that entry. Of course, you have to have your get_absolute_url function defined in your model, but you should have that already, right? :P
In this example entry.body is the content of the blog entry.
{% load blog_filters %}
{{ entry.body|read_more:entry.get_absolute_url }}
If anyone has a better way to do this, it is, of course, welcome.
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
- Template tag - list punctuation for a list of items by shapiromatron 11 months, 1 week ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 2 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
I'll rewrite this as:
#
Please login first before commenting.