Commit c82e17d5 authored by Maël Kervella's avatar Maël Kervella
Browse files

Add support for django-debug-toolbar

parent 2f8ea80e
......@@ -71,4 +71,26 @@ OPTIONAL_APPS = (
\ No newline at end of file
## MR 177: Add django-debug-toolbar support
Add the possibility to enable `django-debug-toolbar` in debug mode. First install the APT package:
apt install pyhton3-django-debug-toolbar
And then activate it for Re2o by adding the app to the `OPTIONAL_APPS` in `re2o/`:
# ...
# ...
If you to restrict the IP which can see the debug, use the `INTERNAL_IPS` options in `re2o/`:
INTERNAL_IPS = ["", ""]
# Re2o est un logiciel d'administration développé initiallement au rezometz. Il
# se veut agnostique au réseau considéré, de manière à être installable en
# quelques clics.
# Copyright © 2018 Maël Kervella
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""Defines the middlewares used in all apps of re2o.
from django.conf import settings
def show_debug_toolbar(request):
"""Middleware to determine wether to show the toolbar.
Compared to `django-debug-toolbar`'s default, add the possibility to allow
any IP to see the debug panel by not setting the `INTERNAL_IPS` options
requests: The request object that must be checked.
The boolean indicating if the debug toolbar should be shown.
if hasattr(settings, 'INTERNAL_IPS') and settings.INTERNAL_IPS and \
request.META.get('REMOTE_ADDR', None) not in settings.INTERNAL_IPS:
return False
return bool(settings.DEBUG)
......@@ -94,6 +94,16 @@ MIDDLEWARE_CLASSES = (
# Include debug_toolbar middleware if activated
if 'debug_toolbar' in INSTALLED_APPS:
# Include this middleware at the beggining
# Change the default show_toolbar middleware
'SHOW_TOOLBAR_CALLBACK': 're2o.middleware.show_debug_toolbar'
# The root url module to define the project URLs
ROOT_URLCONF = 're2o.urls'
......@@ -72,6 +72,12 @@ urlpatterns = [
include('preferences.urls', namespace='preferences')
# Add debug_toolbar URLs if activated
if 'debug_toolbar' in settings.INSTALLED_APPS:
import debug_toolbar
urlpatterns += [
url(r'^__debug__/', include(debug_toolbar.urls)),
if 'api' in settings.INSTALLED_APPS:
urlpatterns += [
url(r'^api/', include('api.urls', namespace='api')),
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment