Thursday, October 8, 2015

Overriding template view function in Django app.

I have installed third party app(Mezzanine) whose urls are configured to use their view functions not View Class. Source code from mezzanine.blog.urls

       urlpatterns = patterns("mezzanine.blog.views",  16   url("^%stag/(?P<tag>.*)%s$" % _slashes, "blog_post_list",
21        name="blog_post_list_tag"),
18 ... 44)
As we can see they have configured blog URLs to use mezzanine.blog.views. Here we have few functions which are being called by URL dispatcher.  one of them is below.
       def blog_post_list(request, tag=None, year=None, month=None, username=None,  20                   category=None, template="blog/blog_post_list.html",  21                   extra_context=None):  22    """  23    Display a list of blog posts that are filtered by tag, year, month,  24    author or category. Custom templates are checked for using the name  25    ``blog/blog_post_list_XXX.html`` where ``XXX`` is either the  26    category slug or author's username if given.  27    """
I would like to override this function so that it will call my function to update context dictionary  or pass some more arguments to default function blog_post_list (it's having an argument extra_context so we can use this as external context) 

How can I achieve this ?
 Please provide complete details like do we have to modify urlpatterns then what should be changed, if we have to change view then what should be change ?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/47eabec2-fdb1-47a8-b9f8-8f158c29852f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment