Search code examples
pythonjquerydjangoofflinedjango-debug-toolbar

Django debug toolbar 1.8 offline mode


I started using django debug toolbar 1.8 in a project with django 1.11.17, everything goes well until I tried to use it from home (is not showing at all) where I don't have internet, that is the only difference I can think of. Any ideas?


Solution

  • This is what I have found out, django debug toolbar 1.8 still depends on jquery and is trying to get it from ajax.googleapis.com so that's where the problem is.

    Reading the docs on https://django-debug-toolbar.readthedocs.io/en/latest/changes.html#id19 I learn that since django debug toolbar 1.2, jquery is not bundled on the code

    1.2 (2014-04-25)

    New features

    The JQUERY_URL setting defines where the toolbar loads jQuery from.
    

    Current value in the code:

    'JQUERY_URL': '//ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js'
    

    Solution:

    1. Download a copy of jquery and serve it locally

    Download the contents https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js and save it on a file named jquery-2.2.4.min.js. Open a terminal in the folder where the file is and run:

    For python 2.x

    python -m SimpleHTTPServer 2000
    

    For python 3.x

    python -m http.server 2000
    
    1. Configure your project to work offline

    Put this on settings.py

    DEBUG_TOOLBAR_CONFIG = {
     'JQUERY_URL': '//localhost:2000/jquery-2.2.4.min.js'
    }
    

    Just run your server and start debugging!!!