Looking good! Thank you for sharing your solution.
Nit-picky, perhaps, but in the page_teaser method I prefer try/except/else,
e.g.:
try:
page = Page.objects.get(slug=slug)
except DoesNotExist:
return None
else:
return page
Python's try/except/else/finally
<https://docs.python.org/2/tutorial/errors.html#handling-exceptions> is
worth sharing.
On Thu, Apr 9, 2015 at 4:16 PM, roland balint <[email protected]> wrote:
> Thanks to all involved it is working!
>
> index.html
>
> {% include "teaser.html" %}
>
>
> teaser.html
>
> {% load page_teaser_tags keyword_tags mezzanine_tags i18n %}
>
> {% page_teaser "about-us" as teased_page %}
> {% if teased_page %}
> <p>{{ teased_page.description|safe|truncatechars:50 }}</p>
> {% endif %}
>
>
> page_teaser_tags.py
>
> from __future__ import unicode_literals
>
> from mezzanine.pages.models import Page
> from mezzanine import template
>
> register = template.Library()
>
> @register.as_tag
> def page_teaser(slug=''):
> """
> return the requested page
> usage
> {% page_teaser "about-us" as page_teased %}
> """
> if slug:
> try:
> page = Page.objects.get(slug=slug)
> return page
> except page.DoesNotExist:
> return None
> return None
>
> --
> You received this message because you are subscribed to the Google Groups
> "Mezzanine Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.