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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:02:41+00:00 2026-05-12T11:02:41+00:00

This is a very similar question to this SO thread on middleware and views

  • 0

This is a very similar question to this SO thread on middleware and views communicating

We’d like to have our templates be given a standard set of context variables. So, a context processor seems appropriate, however, it doesn’t seem like the context processor is view-aware. We’d previously been forced to inspect the call stack to get contextual information on what view was doing what.

That’s where we saw the middleware thread as well as the process_view() signature for a middleware that gives us a handle to the view.

This seemed closer to our needs, but didn’t allow us to modify the context variable, neither did the other middleware methods.

So our intial idea bandied about was to modify the request object with all the global and contextual information we needed for our templates and force the templates to call from the {{request.something}} for the specific information we need, such as {{request.viewname}}.

So, our questions:

  • Is modifying/setting values on the request object an accepted thing to do for pushing contextual/global app specific information to your templates? Or is the standard practice always to put it into contexts?
  • Are there ways/tricks to make context processors view aware that don’t involve passing it explicitly or doing some stack introspection?
  • Does the middleware.process_response have an opportunity to modify the context or is it immutable?
  • 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-12T11:02:41+00:00Added an answer on May 12, 2026 at 11:02 am

    It’s perfectly valid to set variables on the request in middleware – I do it all the time.

    There’s no way to use process_response for this, as by then the template has already been rendered – at this point all you get is an HttpResponse containing a bunch of HTML.

    An alternative might be to wrap render_to_response with your own function, which takes the context, together with the request and template, and modifies it as necessary before handing off to the actual render function. This has the advantage of modifying the actual context, but the disadvantage that you have to actually remember to call it in every view instead of the default function.

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

Sidebar

Related Questions

Liu Chang asked a very similar question to this one here, Linux equivalent of
Very similar to this question , except for Java. What is the recommended way
This question is very similar to SQL Server 2005: T-SQL to temporarily disable a
I'm sorry for this very newbish question, I'm not much given into web development.
(this question is very similar to my previous question Does it matter where I
This is a very similar question to AJAX, Subdomains and the 200 OK response
Have a look at this very simple example WPF program: <Window x:Class=WpfApplication1.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
This is almost similar question to this one: - Dealing with timezones in PHP
This question is similar to this one about animation queues , but the answers
The accepted answer to this question , and a similar discussion at work today

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.