Reputation: 1531
To be clear, the debug toolbar DOES appear. My problem is that when I enable the Debug Toolbar, all my javascript and css files fail to load.
My page loses all formatting but does still load the content. I am using chrome, which under the console prints something like this:
Failed to load resource: the server responded with a status of 404 (NOT FOUND) http://127.0.0.1:8000/static/stylesheets/loggedin.css?h=201e99 Failed to load resource: the server responded with a status of 404 (NOT FOUND) http://127.0.0.1:8000/static/stylesheets/estimates.tabs.css?h=64c8f9 Failed to load resource: the server responded with a status of 404 (NOT FOUND) http://127.0.0.1:8000/static/js/jquery.console-log.js Failed to load resource: the server responded with a status of 404 (NOT FOUND) http://127.0.0.1:8000/static/theme/jquery-ui.custom.css Failed to load resource: the server responded with a status of 404 (NOT FOUND) http://127.0.0.1:8000/static/js/jquery-ui-timepicker-addon.js?h=7e5e4a Failed to load resource: the server responded with a status of 404 (NOT FOUND) http://127.0.0.1:8000/static/js/jquery.if.min.js?h=e69918 Failed to load resource: the server responded with a status of 404 (NOT FOUND) http://127.0.0.1:8000/static/js/base.js?h=4b783f Failed to load resource: the server responded with a status of 404 (NOT FOUND) http://127.0.0.1:8000/static/stylesheets/estimates.summary.show.css?h=0dd5d5 Failed to load resource: the server responded with a status of 404 (NOT FOUND) http://127.0.0.1:8000/static/js/jquery.floatThead.min.js?h=7f4ca5 Failed to load resource: the server responded with a status of 404 (NOT FOUND) http://127.0.0.1:8000/static/stylesheets/reset.css?h=fbd5ac Failed to load resource: the server responded with a status of 404 (NOT FOUND) http://127.0.0.1:8000/static/js/estimates.section.sortable.js?h=2ea052 Failed to load resource: the server responded with a status of 404 (NOT FOUND) http://127.0.0.1:8000/static/stylesheets/loggedin.css?h=201e99 Failed to load resource: the server responded with a status of 404 (NOT FOUND) http://127.0.0.1:8000/static/stylesheets/estimates.tabs.css?h=64c8f9 Failed to load resource: the server responded with a status of 404 (NOT FOUND) http://127.0.0.1:8000/static/stylesheets/estimates.summary.show.css?h=0dd5d5 Failed to load resource: the server responded with a status of 404 (NOT FOUND) http://127.0.0.1:8000/static/stylesheets/reset.css?h=fbd5ac Failed to load resource: the server responded with a status of 404 (NOT FOUND) http://127.0.0.1:8000/static/stylesheets/base.css?h=fcefb2 Failed to load resource: the server responded with a status of 404 (NOT FOUND) http://127.0.0.1:8000/static/theme/jquery-ui.custom.css Failed to load resource: the server responded with a status of 404 (NOT FOUND)
I am using debug_toolbar 1.3.2, django1.5.0 and python 2.7.6
My project structure has
project_dir
project
settings
settings.py
static
images
js
scss
stylesheets
In my settings file:
DEBUG = True
DEBUG_TOOLBAR = True
#....middleware
#....other Installed apps
cd_up = lambda x: os.path.split(x)[0]
SETTINGS_DIR = dirname(os.path.abspath(__file__))
APP_DIR = cd_up(SETTINGS_DIR)
PROJ_DIR = cd_up(APP_DIR)
MEDIA_ROOT = '/tmp'
MEDIA_URL = ''
STATIC_URL = '/static/'
STATIC_ROOT = '{}/static/'.format(APP_DIR)
if DEBUG_TOOLBAR:
INSTALLED_APPS += ('django.contrib.staticfiles','debug_toolbar',)
MIDDLEWARE_CLASSES += debug_toolbar.middleware.DebugToolbarMiddleware',)
INTERNAL_IPS = ('127.0.0.1',)
DEBUG_TOOLBAR_PANELS = (
#'debug_toolbar.panels.version.VersionDebugPanel',
#'debug_toolbar.panels.timer.TimerDebugPanel',
#'debug_toolbar.panels.settings_vars.SettingsVarsDebugPanel',
#'debug_toolbar.panels.headers.HeaderDebugPanel',
#'debug_toolbar.panels.request_vars.RequestVarsDebugPanel',
#'debug_toolbar.panels.template.TemplateDebugPanel',
'debug_toolbar.panels.sql.SQLDebugPanel',
#'debug_toolbar.panels.signals.SignalDebugPanel',
#'debug_toolbar.panels.logger.LoggingPanel',
)
Naturally I cannot send any ajax request and setting DEBUG_TOOLBAR to false resolves all issues.
This is a condensed version, but if any other information is needed I'll update. Sorry, I'm still kind of new to SO. Thanks
UPDATE: The 404 errors appear when running ./manage.py runserver --insecure
Otherwise the resource fails with a message of net::ERR_NETWORK_CONNECTION_RESET
Upvotes: 1
Views: 3473
Reputation: 46
I think this happens when you are using a virtual environment. The problem is that Django packages are installed there and the project can't access the files. You can fix that by running (based on your python version) python3 manage.py collectstatic in the console. This is how I fixed this problem on my end. Hope it helps your case
Upvotes: 1
Reputation: 18563
I am not sure what is happening, but here are a few points to check:
When DEBUG_TOOLBAR is false, is django.contrib.staticfiles
in INSTALLED_APPS? If it was added, this line
INSTALLED_APPS += ('django.contrib.staticfiles','debug_toolbar',)
can cause a duplicate app name. It should not cause any problem, but you can try removing the duplicate.
Are you sure DEBUG is set to True? When DEBUG is False, the development server refuse to serve static files (CONNECTION RESET?), and if you add --insecure option, it serves static files. This is like what you described.
Have you overrided the url mapping of "/static/" in urls.py?
Are you starting this server in a virtual machine? If so, you can try starting your server with:
python manage.py runserver 0.0.0.0:8000
and add your virtual machine's IP addresses to INTERNAL_IP.
Upvotes: 1