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

Redirect Middleware not working - Django

I created a simple redirect middleware class RedirectMiddleware(object): def urlredirect(self, request): path = self.request.build_absolute_uri() if "something" in path: URL = "http://www.someurl.com" else: …
user3854113
0
votes
1 answer

Django call custom middleware only when user is logged in

I have custom middleware installed in settings.py file as shown below. My question is how can this middleware be called only when a user logs in.I can get rid of my try/catch block in the custom middleware get_username only when user is logged…
Rajeev
  • 44,985
  • 76
  • 186
  • 285
0
votes
1 answer

How can I override part of csrf.py middleware?

I want to override Django csrf.py middleware; just a part of it. So I can customize the cookies (or even allow connections without cookies under specific conditions). How could I do that?? Thanks
Sascuash
  • 3,661
  • 10
  • 46
  • 65
0
votes
1 answer

Deactivate middleware at runtime in django

Is it possible to deactivate a middleware on runtime (after starting the application) in django?
mustafa.yavuz
  • 1,274
  • 2
  • 21
  • 40
0
votes
1 answer

Django LocaleMiddleware does not add slash with APPEND_SLASH enabled

I've encountered a problem using LocaleMiddleware in django 1.6. It does not add extra slash event if settings.APPEND_SLASH is set to True. The text error text is: Request Method: GET Request URL: http://pollina.ru/ua/add Django Version: …
1099511627776
  • 176
  • 1
  • 18
0
votes
0 answers

Django redirect within my code without changing display url and send right status code

I'll like to redirect the url like my admin using subdomain without changing the url admin.example.com so in my middleware ill change this to example.com/admin but still display the url as if there was no redirect. here is what my…
user1940979
  • 895
  • 1
  • 13
  • 29
0
votes
2 answers

Django Middleware, single action after login

Let's say I created a Middleware which should redirect user after login to a view with "next" parameter taken from LOGIN_REDIRECT_URL. But it should do it only once directly after logging, not with every request to LOGIN_REDIRECT_URL. At the moment…
mdargacz
  • 1,267
  • 18
  • 32
0
votes
0 answers

Django middleware is causing internal server error in server but runs in debug mode

I have created a custom middleware in Django with following files: models.py with one model. views.py with following code: class UserRequestClass(object): def process_request(self, request): try: user_request =…
Sudip Kafle
  • 4,286
  • 5
  • 36
  • 49
0
votes
1 answer

Site enters into Redirect loop when using HTTP HttpResponsePermanentRedirect in django middleware

I am getting redirect loop with this code in my website when I try to deploy on Heroku. Here is the code for the middleware # -*- coding: utf-8 -*- from django.utils.functional import SimpleLazyObject from django.conf import settings from…
Vinit Kumar
  • 517
  • 6
  • 15
0
votes
1 answer

request.session attribute has disappeared in Django

So I was re-factoring my code (because it was so ugly I could not leave with it). And without touching the settings.py the SessionMiddleware stopped existing for Django. This traceback is after I removed any other middleware that needed sessions. It…
le-doude
  • 3,345
  • 2
  • 25
  • 55
0
votes
1 answer

Broken request (or "broken link" report in Django)?

I received strange broken link report: Subject: Broken link on googleads.g.doubleclick.net Referrer: (url on **my** site!) Requested URL: /pagead/ads?(...) User agent: (...) IP address: (some foreign country) So I took a look at CommonMiddleware,…
Tomasz Zieliński
  • 16,136
  • 7
  • 59
  • 83
0
votes
1 answer

django: How to create Terms of Agreement

I am working with a site which is already connected to single sign on system. Now I want to add terms of agreement page. Here is the flow that I am thinking of: If I have a record of the user who is logging in that means the user has already seen…
add-semi-colons
  • 18,094
  • 55
  • 145
  • 232
0
votes
2 answers

django: Show a agreement page if user is new to the system

I am building an application using django and I am using a single signon system as my authentication system. I want to make sure if user has never been to the site that means If I don't have a record in my table prior to creating a record show a…
add-semi-colons
  • 18,094
  • 55
  • 145
  • 232
0
votes
1 answer

Check id of foreign key object

Im trying to write a function to check that the user has correct member category. My models: from django.db import models from django.contrib.auth.models import User class Membercategory(models.Model): membercatname =…
Tomas Jacobsen
  • 2,368
  • 6
  • 37
  • 81
0
votes
0 answers

Django Internal Server Error in Custom Auth

I wrote a custom auth script and it is giving me an Internal Server error, not quite sure what is causing this or how to get detailed error reporting. allowed_hosts is set to [] but DEBUG is set to True so that shouldn't matter. I'm accessing the…
MatthewKremer
  • 1,549
  • 1
  • 14
  • 25