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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:56:03+00:00 2026-05-27T23:56:03+00:00

Suppose this is what we want in every page, we’d create base_template.html <title>{% block

  • 0

Suppose this is what we want in every page, we’d create “base_template.html”

    <title>{% block title %}{{ page_title }}{% endblock %}</title>

    <a href="http://{{domain}}{{current_path}}">{{ page_title }}</a>{% endblock %}

Instead of passing page_title, domain, current_path from every view function such as:

def display_meta(request):
    user_meta = request.META.items()
    sorted_meta = sorted(user_meta)     # a list of tuples
    return render_to_response('meta.html', {'sorted_meta': sorted_meta, 
                              'current_path': request.get_full_path(), 
                              'domain': request.get_host(),
                              'page_title': display_meta.__name__})
# and repeat the dictionary same manner for other views....

#urls.py
('^book_list/$', 'object_get_list', {'model': models.Book}),

A different approach is wrapping view functions

# urls.py
('^book_list/$', views.get_template(views.object_get_list),{'model': models.Book}),

# views.py
def get_template(view, **extrakw):

    def wrapview(request, **extrakw):
        template_dict = {'current_path': request.get_full_path(), 'domain': request.get_host()}
        extrakw['template_dict'] = template_dict
        return view(request, **extrakw)
    return wrapview


def object_get_list(request, **kwargs):
    model = kwargs.pop('model', None)
    model_name = model.__name__.lower()
    template_dict = kwargs.pop('template_dict', None)
    template_dict[model_name] = model.objects.all()
    template_dict['page_title'] = model_name +" list"
    template_name = '%s.html' %(model_name)
    return render_to_response(template_name, template_dict)

Pro: Besides editing htmls, now modification is done in just one view, instead of every view.

Cons: Ugly URLConf and probably error propne too

Attempt 3:
Create a global dictionary just like template_dict I created.

template_dict = {/..../}

def view1()
def view2() ...

Problem: I can’t use request.path (or anything has to do with request). This falls back to the previous attempt (wrapper).

But there must be an easier way. What is the proper way of passing global template variables throughout a django site so each view function is now indepenednt of gloabl templat variables?

Thank you for you time.

  • 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-27T23:56:03+00:00Added an answer on May 27, 2026 at 11:56 pm

    Use a context processor.

    Add the name of your function to TEMPLATE_CONTEXT_PROCESSORS in settings.py.

    A simple context processor I use is:

    def common_request_parameters(request):
        return {'home_login_form': AuthenticationForm(request)}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have this feature branch foo. Now I want to merge it back
Suppose you want to throw Exception like this: 'Project with the provided ID cannot
I stumbled across this problem in F#. Suppose, I want to declare two types
Of course most languages have library functions for this, but suppose I want to
Suppose that for every Form in a WinForms application, you want to change the
Suppose this C# code: using (MemoryStream stream = new MemoryStream()) { StreamWriter normalWriter =
Suppose this is my URL route: (r'^test/?$','hello.life.views.test'), How do I make it so that
I suppose this question could just as easily be applied to PHP with regard
I suppose this question is a variation on a theme , but different. Torrents
I suppose this might be similar to this question , but I'm wondering if

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.