Questions tagged [django-middleware]

Middleware is a framework of hooks into Django’s request/response processing. It’s a light, low-level “plugin” system for globally altering Django’s input and/or output.

Middleware is a framework of hooks into Django’s request/response processing. It’s a light, low-level “plugin” system for globally altering Django’s input and/or output. Each middleware component is responsible for doing some specific function.

Django ships with some built-in middleware you can use right out of the box; they’re documented in the built-in middleware reference.

455 questions
0
votes
1 answer

What is the scope of Django's Middlewares?

What is the scope of Django's Middleware objects? I wish to know if the Middleware objects are initialized for every request. Relevance: While trying to use SQLAlchemy ORM along with Django, one needs to point a callable object as the scope marker…
Kalaivanan
  • 111
  • 3
0
votes
0 answers

Printing Time spent on a view in Django

I have a simple django view which just reads the request and prints it out into the console. Now along with the request body I need to get the start time of the view for a particular session and if after the session has been terminated or there is…
0
votes
1 answer

High response time when setting value for Django settings module inside a middleware

In a Django project of mine, I've written a middleware that performs an operation for every app user. I've noticed that the response time balloons up if I write the following at the start of the middleware module: import…
Hassan Baig
  • 15,055
  • 27
  • 102
  • 205
0
votes
1 answer

Accessing a django model in middleware (django>1.7)

I'm upgrading from django 1.6.5 to django 1.9, and in the process upgrading several middleware classes. Some of those middleware classes use models during the process_request or process_response phases. However, I'm getting a AppRegistryNotReady:…
mklauber
  • 1,126
  • 10
  • 19
0
votes
0 answers

Proper way to retrieve middleware values

I'm trying to retrieve some loading times per view and displaying it in the page. To do so I'm using a middleware and a context_processor setup but I can't find the way to retrieve this values to the context of the view. Here is the example: I've…
Rod
  • 90
  • 8
0
votes
1 answer

Attribute error for PersonalInfoForm

I'm a little confused why is 'clickjacking middleware` trowing Attribute Error on my form. I'm making a simple application for collecting labor or user information, and I'm facing a small problem, can someone please help me and clarify what is wrong…
copser
  • 2,523
  • 5
  • 38
  • 73
0
votes
1 answer

any middleware in django to perform the abilities of security.yml in symfony2?

Can i declare the auth for all the apis in django, group wise from one file just like security.yml allows us in symfony2
Patlola Praveen
  • 770
  • 9
  • 19
0
votes
0 answers

decorate or wrap the return value of a model field attribute

Suppose I have a Person model: class Person(models.Model): first_name = models.TextField() last_name = models.TextField() I need a way to wrap first_name and last_name at a request-response layer (e.g through middleware). For example, I may…
leonsas
  • 4,718
  • 6
  • 43
  • 70
0
votes
0 answers

Django: Strange HTTP Status codes for non-existing URLS

I have a Django website with activated translations (django.middleware.locale.LocaleMiddleware), I someone requests a non-existing page: https://example.com/nonexisting Django then responds with: HTTP/1.1 302 FOUND Date: Fri, 02 Sep 2016 09:15:45…
caliph
  • 1,389
  • 3
  • 27
  • 52
0
votes
0 answers

Best way to pass data from a middleware to views in Django without modifying request object

I am new to Django and I want to send some information to my views function from the Middleware which I have created inside my Project. Is there any way of doing this specific task and if not How can we modify the request object?? Thanks
0
votes
2 answers

How to execute code after authentication in Django?

I want to execute one or more functions after a user logs into my site. How is this possible? I looked into Middleware. Djangobook says that I'll need this to run a piece of code on each and every request that Django handles. However, I just need…
0
votes
1 answer

middleware does an infinite redirect

I've already read this but the answer doesnt fit my needs. I've made this very simple middleware: class RedirectIfUserIsNotActiveMiddleware(object): """ Middleware to redirect if account is disabled """ @staticmethod def…
Olivier Pons
  • 15,363
  • 26
  • 117
  • 213
0
votes
1 answer

Gzip error with django latest version

I get an error when i include the line "django.middleware.gzip" under the middleware section in settings.py in the django framework. I checked the gzip file location in the nginx server , its present and looks correct. I am getting a 500 internal…
dreamer
  • 478
  • 1
  • 11
  • 24
0
votes
1 answer

How do I track user sessions in my own middleware in django?

Django's session middleware only assigns a session key when the session is first saved. How do I use the session key in my own middleware?
Darren
  • 2,888
  • 1
  • 23
  • 34
0
votes
1 answer

Django custom middleware

I am trying to make a custom middleware class that will check token from cookie with another data (not the point where this data is) and return username or some error. I guess it should be done in process_request method, but how to give this…
massive_dynamic
  • 336
  • 3
  • 5
  • 15