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
2
votes
2 answers

How to profile Django middleware itself?

There are many ways to profile Django views. For example custom middleware or this custom tab for Django Debug toolbar. What is the way to profile django middleware itself?
Daniil Ryzhkov
  • 7,416
  • 2
  • 41
  • 58
2
votes
1 answer

How to pass CSRF token between django applications by reading it from request using urllib

How to pass CSRF token between Django applications by reading it from request using urllib. I am having two servers running with Django applications, based on URL need to send request to other server and give the response back. Django middelware…
Raghvendra Parashar
  • 3,883
  • 1
  • 23
  • 36
2
votes
1 answer

How to add/change django template folder on per-request basis?

We've just started the complete redesign of our project's HTML pages (responsive layout and stuff) and all we need to change is templates and static (css and some js). Views ain't gonna change at all. I want to create all the new templates in…
Sleamey
  • 25
  • 4
2
votes
1 answer

Error with django middleware

I am trying to select database dynamically with help of a middleware(which sets a variable in threading.local) and a dbrouter(which sets the database depending upon the variable set in threading.local). The code goes on like this: import re import…
Vijay Shanker
  • 417
  • 4
  • 10
2
votes
0 answers

django context request error when USE_I18N is True

I use website with 2 languages, and i get this error: 2014-12-07 03:05:51: (mod_fastcgi.c.2695) FastCGI-stderr: File "/home/ikresoft/oglasise/web/templatetags/web_tags.py", line 157, in main_menu 2014-12-07 03:05:51: (mod_fastcgi.c.2695)…
Mirza Delic
  • 4,119
  • 12
  • 55
  • 86
2
votes
2 answers

How to change db in django depending on request.get_host()?

I am creating multisites platform. Anybody can make simple site, with my platform. I plan to use django multidb support. One db for one site. And i need to change db settings depending on request.get_host(). I think that i's not good idea. Prompt…
Alexandr
  • 381
  • 1
  • 5
  • 13
2
votes
3 answers

Django: What is the stack order in Django?

I think that is the right way to ask it. I'm wondering which parts of the code execute first, second, etc. My assumption would be, but I don't know: Request Middleware View Model Middleware Response The reason I'm asking is because I want…
orokusaki
  • 55,146
  • 59
  • 179
  • 257
2
votes
1 answer

Conditional Url Pattern for Django

I have a problem where i have to send two urls of partially same format to different views. eg. "domain/land/one-brush" will go to views.land(request, id) where id is "one-brush" and similarly domain/land/one-brush/include/images/dot.jpg will be…
Manoj hans
  • 1,705
  • 3
  • 11
  • 8
2
votes
1 answer

Django last visited urls list

I'm writing django-based forum, and i've decided it would be suitable for user to browse his last pages. Also, user tracking middleware can be a good aid for suggestions, and so on. I think, the easiest way to do it is to use the Django Middleware,…
2
votes
1 answer

django custom authentication backend with custom middleware (both username,password and token absed auth)

I am in a situation where I need to make a custom authentication and custom middleware to authenticate and authorize the user. I have to chek the username password params in the POST request or if the cookie is set or not for token based…
Maverick
  • 2,738
  • 24
  • 91
  • 157
2
votes
0 answers

Django 1.5 transaction middleware : do you need to use it?

we have this super weird issue happening with postgres that only happens on random requests. We get an InterfaceError: connection already closed which seems to be being thrown by the TransactionMiddleware. This was causing random 500 pages for the…
Werda
  • 279
  • 1
  • 3
  • 9
2
votes
3 answers

New Django middleware not getting called

I am quite new to web development. I am working on a website hosted on amazon ec2 server. The site is in python using django framework. I am using memcached to cache some client information. My site and caching works on local machine but not on the…
Mayank
  • 357
  • 3
  • 17
2
votes
2 answers

cProfiler Django middleware: sorting the stats

In Django, I am using the below middleware Cprofiler snippet /from http://djangosnippets.org/snippets/727/ ) How do I change what is used to sort it? If I want to use sort_stats() where does that go in the code? import sys import cProfile from…
user984003
  • 28,050
  • 64
  • 189
  • 285
2
votes
1 answer

Browser delay with changing content of the page in django admin (caching, python/django)

I have a bit weird problem witch caching on my project in django. I can edit my page-content in django-admin. When i do that and refresh site - nothing is happening. I have to wait few minutes for changes. Funny thing is that, when i change browser…
Auuron
  • 71
  • 3
2
votes
3 answers

How to restrict users voting on their own model

I am using django-voting as a voting application for two of my models. Those both models have fields "author". How can I restrict a user from voting on a model that has this particular user set as it's author without modifying django-voting…
aleksandar
  • 31
  • 5