django-middleware

Redirection to previous page after login using LoginRequiredMiddleware

Redirection to previous page after login using LoginRequiredMiddleware Question: I used to use next_param = request.POST.get(‘next’) to redirect users to their previous page after they log in. I however, decided to go fancier with my code and now force any unauthenticated user to login by using LoginRequiredMiddleware: users are automatically redirected to login page if …

Total answers: 1

Django: "No module named context_processors" error after reboot

Django: "No module named context_processors" error after reboot Question: I have a Django site that works on my PC, and was working briefly on my server after loading it on. I noticed my server had Django 1.6 and I upgraded to 1.8. After rebooting, none of the pages on my site load and I get …

Total answers: 5

How to set up custom middleware in Django

How to set up custom middleware in Django Question: I am trying to create middleware to optionally pass a kwarg to every view that meets a condition. The problem is that I cannot find an example of how to set up the middleware. I have seen classes that override the method I want to, process_view: …

Total answers: 5

Python and Django OperationalError (2006, 'MySQL server has gone away')

Python and Django OperationalError (2006, 'MySQL server has gone away') Question: Original: I have recently started getting MySQL OperationalErrors from some of my old code and cannot seem to trace back the problem. Since it was working before, I thought it may have been a software update that broke something. I am using python 2.7 …

Total answers: 13

Where to put Django startup code?

Where to put Django startup code? Question: I’d like to have these lines of code executed on server startup (both development and production): from django.core import management management.call_command(‘syncdb’, interactive=False) Putting it in settings.py doesn’t work, as it requires the settings to be loaded already. Putting them in a view and accessing that view externally doesn’t …

Total answers: 6

Change Django Templates Based on User-Agent

Change Django Templates Based on User-Agent Question: I’ve made a Django site, but I’ve drank the Koolaid and I want to make an IPhone version. After putting much thought into I’ve come up with two options: Make a whole other site, like i.xxxx.com. Tie it into the same database using Django’s sites framework. Find some …

Total answers: 9