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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:08:22+00:00 2026-05-22T02:08:22+00:00

this my middleware code : from django.conf import settings from django.template import RequestContext class

  • 0

this my middleware code :

from django.conf import settings
from django.template import RequestContext

class BeforeFilter(object):
    def process_request(self, request):
        settings.my_var = 'Hello World'
        request.ss = 'ssssssssss'
        return None
    def process_response(self, request, response):

        return response

this is the settings.py:

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.core.context_processors.request',
)
MIDDLEWARE_CLASSES = (
    ...
    'middleware.BeforeFilter',
)

and the view is :

#coding:utf-8

from django.conf import settings
from django.shortcuts import render_to_response

from django.http import HttpResponse 
from django.template import RequestContext


def index(request):
    context = RequestContext(request)
    context['a'] = 'aaaa'
    return render_to_response('a.html',context)

the html is :

{{a}}fffff{{ss}}

but it not show {{ss}}:

aaaafffff 

so how do i show :

aaaafffffssssssss

how to insert some text in all django context using django middleware,

so that i cant use to insert the text everytime ,

thanks

  • 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-22T02:08:23+00:00Added an answer on May 22, 2026 at 2:08 am

    To meet your initial goal, I do not think the BeforeFilter middle ware is required. What we need is just a template context processor.

    Write a context processor as following:

    #file: context_processors.py
    
    def sample_context_processor(request):
       return {'ss':'ssssssssss'} #or whatever you want to set to variable ss
    

    then add the context processor to TEMPLATE_CONTEXT_PROCESSORS list

    #file: settings.py 
    
    TEMPLATE_CONTEXT_PROCESSORS = (
        'myproject.context_processors.sample_context_processor',
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a snippet of code from django.core.exceptions : class MiddlewareNotUsed(Exception): This middleware is
I have a snippet of code like this in a Django application def update_account(user_account,add_widget_count):
I use Django 1.3. I have a clean project with: settings.py import os, sys
I've a problem with django csrf middleware... when I use the template tag csrf_token
Django internationalization allows me to set a language code either in settings file (site-wide)
i have a problem, i tried this code : private void button1_Click(object sender, RoutedEventArgs
I am using this middleware to make my app restful, but it looks like
This is a very similar question to this SO thread on middleware and views
This is my first post here and I wanted to get some input from
I've got a simple POCO class to hold data extracted from an XML file

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.