Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8084199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:42:56+00:00 2026-06-05T17:42:56+00:00

I have included Django comments framework in my project, and added custom templates to

  • 0

I have included Django comments framework in my project, and added custom templates to include my base template instead of the default one.

However, in my base template, there are a few url template tags with dynamic parameters:

{% url galleries blog.pk blog.slug %}

Variable blog is included in the context in my views, but not in the comments framework, which causes No reverse match error when I try to add a comment.

What would be the best way to get variable blog always included in the base template?

Update:

url patterns for blog app:

url(r'^(?P<blog_id>\d+)/(?P<slug>[\-\d\w]+)/galleries/$', 'galleries', name = 'galleries'),
(r'^comments/', include('django.contrib.comments.urls')),
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T17:42:58+00:00Added an answer on June 5, 2026 at 5:42 pm

    Create yourself a context processor. These are just functions that return a dict whose items will be available anywhere in your templates. Typically you will create a context_processor.py file in the relevant Django app, then include this in your TEMPLATE_CONTEXT_PROCESSORS setting.

    E.g.:

    project/myapp/context_processors.py:

    def blog(request):
        return {
            'blog': get_blog(),
        }
    

    In your settings:

    TEMPLATE_CONTEXT_PROCESSORS = (
        # ... standard django ones here ...
        'project.myapp.context_processors.blog',
    )
    

    Now blog will be available in all your templates.

    EDIT: I forgot that these context processor methods receive the request as an argument which lets you do more powerful stuff.

    EDIT 2: Per your update showing the URL patterns… You could create a piece of middleware that picked off the blog_id from the kwargs and add it to the request object:

    class BlogMiddleware(object):
        def process_view(self, request, view_func, view_args, view_kwargs):
             blog_id = view_kwargs.pop('blog_id', None)
             if blog_id:
                 request.blog = Blog.objects.get(id=blog_id)
    

    Now you can access the blog in the templates using either {{ request.blog }} or you could use the context processor still.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have problem with django's named urls which is included with include keyword. In
I have a django 1.4 project with 2 apps: RemoteStorage and WeShouldServer (that one
I'm having an issue with django templates at the moment. I have 3 template
I'd like to modify the existing Django comments framework to include star ratings. The
Is it possible to have multiple models included in a single ModelForm in django?
I have two apps in my Django project: a public-facing app, and a management
I have included a new app django_colorbox in my Pinax project. For some reason
I have a Django application which includes a custom model field (and accompanying form
I have project in Django 1.3. In order to show username in all pages
In my Django project, I used to have a single URLConf, urls.py at the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.