I would like to see the Django Debug toolbar when accessing my website running Django 1.6. Debian 7.8, Nginx 1.2.1 and Gunicorn 19.1.1 are running on my server. However, when I try to access the site after adding DDT to my installed applications, I get the following error:
NoReverseMatch at / u'djdt' is not a registered namespace Exception Location: /home/mysite/venv/mysite/local/lib/python2.7/site-packages/django/core/urlresolvers.py in reverse, line 505 Error during template rendering In template /home/mysite/venv/mysite/local/lib/python2.7/site-packages/debug_toolbar/templates/debug_toolbar/base.html, error at line 12 data-store-id="{{ toolbar.store_id }}" data-render-panel-url="{% url 'djdt:render_panel' %}"
I know that it is not recommended to run the toolbar during production, but I just want to run it while I run some tests on my production server before opening it for general use. As you would expect, it works fine in my development environment on my laptop. I did some research and made sure to use the โexplicitโ setting as recommended. I also ran the command "django-admin.py collectstatic" to make sure the static toolbar files were compiled into my STATIC_ROOT.
Since I'm running after a proxy server, I also added some middleware to ensure that the client IP address is passed to the toolbar middleware instead of my proxy IP address. This also did not fix the problem.
I show all the settings that apply to this problem below. Is there anything else I am missing?
Thanks!
These are the appropriate basic settings:
SETTINGS_ROOT = os.path.abspath(os.path.dirname(__file__).decode('utf-8')) STATIC_ROOT = '/var/www/mysite/static/' STATIC_URL = '/static/' STATICFILES_DIRS = ( os.path.join(SETTINGS_ROOT, "../../static"), ) STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', ) TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', ) MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.middleware.common.BrokenLinkEmailsMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ) TEMPLATE_DIRS = ( os.path.join(SETTINGS_ROOT, "../../templates"), ) INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', # Django management commands in 'scripts' 'scripts', 'apps.account', )
These production-only settings are added to the basic settings during the production process:
DEBUG = True # DDT needs this to be True TEMPLATE_DEBUG = DEBUG INSTALLED_APPS += ( 'django_extensions', # I'm using Django 1.6 'debug_toolbar', ) if 'debug_toolbar' in INSTALLED_APPS: MIDDLEWARE_CLASSES += ('conf.middleware.DjangoDebugToolbarFix', 'debug_toolbar.middleware.DebugToolbarMiddleware', ) # I had to add this next setting after upgrading my OS to Mavericks DEBUG_TOOLBAR_PATCH_SETTINGS = False # IP for laptop and external IP needed by DDT INTERNAL_IPS = ('76.123.67.152', ) DEBUG_TOOLBAR_CONFIG = { 'DISABLE_PANELS': [ 'debug_toolbar.panels.redirects.RedirectsPanel', ], 'SHOW_TEMPLATE_CONTEXT': True, 'INTERCEPT_REDIRECTS': False }
This is in my urls.py:
if 'debug_toolbar' in dev.INSTALLED_APPS: import debug_toolbar urlpatterns += patterns('', url(r'^__debug__/', include(debug_toolbar.urls)), )
Here is some additional middleware:
class DjangoDebugToolbarFix(object): """Sets 'REMOTE_ADDR' based on 'HTTP_X_FORWARDED_FOR', if the latter is set.""" def process_request(self, request): if 'HTTP_X_FORWARDED_FOR' in request.META: ip = request.META['HTTP_X_FORWARDED_FOR'].split(",")[0].strip() request.META['REMOTE_ADDR'] = ip