Hey Neeraj, it looks like some people have provided you some alternate
solutions, but if you do want to go the page processor route, it is
possible.

Check out the default urls.py provided in your Mezzanine projects.  There
are a couple of urls, the default is just to server index.html.  An
alternate one (that is commented out) is to have your home page be a page
in the page tree.  If you comment out the default and uncomment that one
you can then create a page and give it the slug / (you can set this in the
Meta section of the page admin).  It will then show as the home page and
the original technique you tried to create the page processor should work.


On Tue, Dec 17, 2013 at 6:26 AM, Eduardo Rivas <[email protected]>wrote:

> Hello Neeraj. I've done what you're trying to accomplish several times in
> the past. The solution is to create a template tag that loads your custom
> Articles into the template context. Mezzanine has the {%
> blog_recent_posts 
> %}<https://github.com/stephenmcd/mezzanine/blob/master/mezzanine/blog/templatetags/blog_tags.py#L54>tag
>  that does the same. Mezzanine's implementation goes the extra mile and
> adds author and category filters, but a bare implementation should look
> like this:
>
> First, create a folder "templatetags" in your app folder, with a file
> called news_tags.py and another one called __init__.py. Let's say your app
> is called News and your model is also called News. You should have
> news/templatetags/news_tags.py and __init__.py. The init file is empty and
> exists only to indicate that the templatetags folder should be treated as a
> Python module.
>
> # news_tags.py
> from mezzanine import template
>
> from news.models import News
>
> register = template.Library()
>
>
> @register.as_tag
> def recent_news(limit=4):
>     """
>     Put a list of recently published News into the template context.
>     Usage: {% recent_news 3 as recent_news %}
>     """
>     news = News.objects.published()
>     return list(news[:limit])
>
> The template tag let's you get the latest (published) News objects sliced
> to a custom limit. You can further extend the tag to apply sorting and
> filtering.
>
> # templates/index.html
> {% load news_tags %}
>
> {% recent_news 5 as recent_news %}
> {% for news in recent_news %}
>     <a href="{{news.get_absolute_url}}">{{news.title}}</a></h4>
>     <p>{{news.publish_date|date}}</p>
> {% endfor %}
>
> This will render the 5 most recent news displaying a link to the full
> article and the publish date. This assumes your News model has such fields
> (it will if you've extended Displayable). Again, you can extend it to your
> liking displaying any of the fields available to the News model.
>
> Check out the Django docs on template 
> tags<https://docs.djangoproject.com/en/1.5/howto/custom-template-tags/>and 
> Mezzanine's Displayable
> model<https://mezzanine.readthedocs.org/en/latest/content-architecture.html#non-page-content>.
> Please notice Mezzanine overrides some parts of Django's template tag
> environment, which explains the difference in writing a template tag for
> Mezzanine and Django.
>
> --
> 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/groups/opt_out.
>

-- 
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/groups/opt_out.

Reply via email to