Adventures in Freelancing
Django
Hiding the Django Debug Toolbar in the Admin
Aug 18th
The Django Debug Toolbar is a an extremely helpful tool, but I find it a bit annoying in the admin. Thankfully, it only takes a few lines of code to blacklist the admin section.
Put this in your local_settings file (click the little ‘View Source’ icon in the upper right to easily cut & paste):
import re
def show_toolbar(request):
uri = request.get_full_path()
if re.match(r'/admin/', uri):
return False
return True
DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK': show_toolbar
}
Django How-To: Add Debugging Apps to Your Local Settings
Jun 3rd
There are some great debugging apps, like the django-debug-toolbar and django-command-extensions, that help out immensely while developing your next killer Django site. There’s a small catch to using them though, which is that they have to be added to INSTALLED_APPS. No big deal, but you don’t really want these installed and running in a production install.
Again, no big deal. It’s an old trick now to maintain a separate local_settings.py file. By importing our local_settings at the end of the settings.py module, anything in local_settings will overwrite whatever is in settings.
So all we have to do then is make a new list of debugging apps in local_settings.py, and add them to the INSTALLED_APPS list in settings.py.
My first naive attempt was to do this:
# local_settings.py
INSTALLED_APPS += ('django_extensions',)
Can you spot the problem? The original INSTALLED_APPS is not available in local_settings.py, so we can’t add to it there.
Well, if we can’t add our list in local_settings.py, let’s add in in settings.py
# local_settings.py
DEBUG_APPS = ('django_extensions',)
# settings.py
try:
from local_settings.py import *
INSTALLED_APPS += DEBUG_APPS
except ImportError:
pass
This works just fine, as long as there is a DEBUG_APPS list specified in local_settings.py. However, the whole point of having a local_settings.py file is to optionally add or overwrite settings.
To remove this dependency, More >