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 271579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:11:11+00:00 2026-05-12T00:11:11+00:00

Like a good little coder, all of my Django templates inherit from a base.html.

  • 0

Like a good little coder, all of my Django templates inherit from a base.html. Now I would like to add some functionality to the base to always show some interesting things. Some user statistics, or random posts, or feeds, etc.

All of my views look like this:

def viewname(request) :
    template_vales = {}
    // Stuff
    return render_to_response('some_file_name.html', template_values)

How can I make it so that the values of template_values are always populated for all my views? Do I have to do this at the start of all of my views? As in:

import utils

def viewname(request) :
    template_values = {}
    utils.addDefaults(template_values)
    // Stuff
    return render_to_response('some_file_name.html', template_values)

Or is there a better way?

  • 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-05-12T00:11:11+00:00Added an answer on May 12, 2026 at 12:11 am

    You should use context processors:

    http://docs.djangoproject.com/en/dev/ref/templates/api/

    http://www.b-list.org/weblog/2006/jun/14/django-tips-template-context-processors/

    In my settings.py, I add a couple of functions to the standard ones (see the last two):

    TEMPLATE_CONTEXT_PROCESSORS = (
      "django.core.context_processors.request",
      "django.core.context_processors.auth",
      "django.core.context_processors.debug",
      "django.core.context_processors.i18n",
      "thetrailbehind.context_processors.canonical_url",
      "thetrailbehind.context_processors.gmapkey",)
    

    The first one I add defines the canonical URL for the view, and the second switches between GMap keys. Here’s that function:

    def gmapkey(request):
      url = request.META['HTTP_HOST']
      key = ""
      if url == "127.0.0.1:8000":
        key = "ABQIAAAAGFSvsJjnPmsGb7IcfqoamBTpH3CbXHjuCVmaTc5MkkU4wO1RRhTaJZRNQLjBhGtJlm6eE4gJtku-Rw"   
      elif url ==  "192.168.11.3:8000":
        key = "ABQIAAAAGFSvsJjnPmsGb7IcfqoamBTm8-wcGRt2V-0p00qdRdGeyDhtGBSRTbk2s1ciA8vzdxGeAnqq6g-F4g"
      elif url ==  "192.168.11.17:7000":
        key="ABQIAAAAmHGaJpkZhJ6huJ93yfaYERTmT93Y0kqi8UE3J2QowoLz6rHdtxTHqeJ0nRoENl5LY5gCqHhRK9Yasg"
      elif url == "192.168.1.200:8000":
        key="ABQIAAAAmHGaJpkZhJ6huJ93yfaYERR5_sKpsr8Ui4YjC4HGOe8xaUDeVhSxGV1r1rIL1OvmVMAGUQBoUK0H2w"
      elif url == "192.168.1.73:8000":
        key = "ABQIAAAAGFSvsJjnPmsGb7IcfqoamBR7_CRKSBu49YjvDOLq_-DZQHSIYBSip9sO5IHlFIoZMtDpVcduFQCnWg"
      elif url == "www.trailbehind.com":
        key="ABQIAAAAGFSvsJjnPmsGb7IcfqoamBQxFGSDsNggDdRtUnAb8L8sJ910FhSKwoOpNaUlGCQIhyl6Dy5Cbyb0lQ"
      elif url == "dev.trailbehind.com":
        key="ABQIAAAAmHGaJpkZhJ6huJ93yfaYERQzqIbhF_xOwOwM1oDO_kQqYhag7BRsoTInq2lBuE7fsgDN2xfyD2IL5A"
      elif url == "trailbehind.com":
        key = "ABQIAAAAGFSvsJjnPmsGb7IcfqoamBQL9YYTGyB2pLTiscy54DOfsaXeHBQqMBmq7UvWAZVenmRMtNr_bo3TMQ"
      elif url == "tenuki.trailbehind.com":
        key = "ABQIAAAAGFSvsJjnPmsGb7IcfqoamBQ5SkJUKVREyqcvaNQJsRscGi2yVhSj0mJSTasDiWec8Awxb_TUxOdElw"
      elif url == "cabin.trailbehind.com":
        key = "ABQIAAAAmHGaJpkZhJ6huJ93yfaYERSU-76xxg1tvy-8taAiiF1qqcGi1xSmjUhmAs_v2XAuGxKX_Y-4-gDP3Q"
      elif url == "ec2-174-129-167-234.compute-1.amazonaws.com":
        key = "ABQIAAAAmHGaJpkZhJ6huJ93yfaYERStHq7nubctzsNDgkYc34LoSNrRNhQVCNy2KFFm2BT1sG2yrXrw38ycNg"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello and good day to all. I have a little question about like statement
I am looking to write a an asp.net website and would like a good
Good evening, I would like to have a navigation bar which is centralised to
Would like to know what a programmer should know to become a good at
I like to get inspiration from using web applications that make good use of
First, I have to say that I really like Groovy and all the good
I am relatively new to python (already did some 1h scripts like a little
This is more like a good practise question. I want to offer different generic
I've recently stumbled across geb and it looks like a good way to perform
I am currently evaluating message queue systems and RabbitMq seems like a good candidate,

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.