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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:03:50+00:00 2026-05-11T15:03:50+00:00

I have a Django website as follows: site has several views each view has

  • 0

I have a Django website as follows:

  • site has several views
  • each view has its own template to show its data
  • each template extends a base template
  • base template is the base of the site, has all the JS/CSS and the basic layout

So up until now it’s all good. So now we have the master head of the site (which exists in the base template), and it is common to all the views.

But now I want to make it dynamic, and add some dynamic data to it. On which view do I do this? All my views are basically render_to_response('viewtemplate.html', someContext). So how do add a common view to a base template?

Obviously I will not duplicate the common code to each separate view…

I think I’m missing something fundamental in the MVT basis of Django.

  • 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. 2026-05-11T15:03:51+00:00Added an answer on May 11, 2026 at 3:03 pm

    You want to use context_instance and RequestContexts.

    First, add at the top of your views.py:

    from django.template import RequestContext 

    Then, update all of your views to look like:

    def someview(request, ...)     ...     return render_to_response('viewtemplate.html', someContext, context_instance=RequestContext(request)) 

    In your settings.py, add:

    TEMPLATE_CONTEXT_PROCESSORS = (     'django.core.context_processors.auth',     ...     'myproj.app.context_processors.dynamic',     'myproj.app.context_processors.sidebar',     'myproj.app.context_processors.etc', ) 

    Each of these context_processors is a function takes the request object and returns a context in the form of a dictionary. Just put all the functions in context_processors.py inside the appropriate app. For example, a blog might have a sidebar with a list of recent entries and comments. context_processors.py would just define:

    def sidebar(request):     recent_entry_list = Entry.objects...     recent_comment_list = Comment.objects...     return {'recent_entry_list': recent_entry_list, 'recent_comment_list': recent_comment_list} 

    You can add as many or as few as you like.

    For more, check out the Django Template Docs.

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

Sidebar

Related Questions

I have a Django view, which receives part of its data from an external
I have a Django website that requires users to be logged in to view
I am developing my first django website. I have written code in my view
I'm building a website in Django. I want each user of the site to
For a website implemented in Django/Python we have the following requirement: On a view
I have a Django website in which I want site administrators to be able
I have a corporate website with django-cms and with a SQLite database that has
we have just started using a git account of our Django website project so
I am looking for displaying Forecast information in my Django Website. Do you have
I'm developing an online website (using Django and Mysql). I have a Tests table

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.