Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Django ORM Same Old ORM django-debug-toolbar

Alx Ki
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alx Ki
Python Web Development Techdegree Graduate 14,810 Points

Django Debug Toolbar with PyCharm

  1. I installed django debug toolbar to virtual environment.
  2. I added debug-toolbar to INSTALLED_APPS after django.contrib.staticfiles.
  3. I added debug_toolbar.middleware.DebugToolbarMiddleware to MIDLEWARE as PyCharm said.
  4. I tried Django 1.9.6 and 1.10.4. Toolbar 1.6

No errors, no toolbar.

Please, help, Kenneth Love

Jeff Muday
Jeff Muday
Treehouse Moderator 27,586 Points

I am not using PyCharm. Though, I assume you might be hitting a similar snag I had in another IDE.

Captain Obvious (pointing at me) says make sure you install the debug toolbar.

$ pip install django_debug_toolbar

I had to do a couple of edits to the project files to ensure the toolbar worked.

learning_site/settings.py

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'debug_toolbar', # Added this (Kenneth said so in the video)
    'courses',
)
MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'debug_toolbar.middleware.DebugToolbarMiddleware', # added this line, this Kenneth didn't mention
)

...

INTERNAL_IPS= ['127.0.0.1'] # Kenneth showed this in a video, but also that kinda strange Lambda thing for workspaces

Even after this, I got a namespace error too, so I had to add this into the urls.py

learning_site/urls.py

from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
import debug_toolbar # add this

from . import views

urlpatterns = [
    url(r'^courses/', include('courses.urls', namespace='courses')),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^suggest/$', views.suggestion_view, name='suggestion'),
    url(r'^$', views.hello_world, name='home'),
    url(r'^__debug__/', include(debug_toolbar.urls)), # added this line
]

urlpatterns += staticfiles_urlpatterns()

I hope this helps, Jeff

6 Answers

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 27,586 Points

I am using WingIDE Personal (paid version under $50). It compares favorably to PyCharm in terms of features and Django awareness, and (in my experience) has a snappier response on its various platform offerings (it works brilliantly as I frequently switch between computers and platforms while on the job and when I work from home). The Linux, Mac, and Windows versions have a nearly identical feel.

The free version of WingIDE 101 is not quite refined enough for a serious Django project, but does work.

Jeff Muday
Jeff Muday
Treehouse Moderator 27,586 Points

Those changes I suggested did work for me under PyCharm version 4.5.2

Jeff Muday
Jeff Muday
Treehouse Moderator 27,586 Points

By the way, WingIDE Personal Edition, now in the 6.x version is FREE. It works great and has "Django awareness". Pycharm has improved quite a bit too from a year ago, but I still favor the Wingware offering.

mykolash
mykolash
12,955 Points

Hi fellows,

let me add just few words.

I've occurred such an issue just after debug_tools installing and setup (seems to be similar to yours):

Exception Type: TypeError 

Exception Value: process() missing 1 required positional argument: 'stream'

And fixed it. Tried different debug_tool versions - it's NOT debug_tool issue. Seems to be it's SQLParse issue.

So, I did two things: (Working on Windows10 - but I guess it deals nothing w/ OS)

  1. Explicit setup of debug_tool: https://django-debug-toolbar.readthedocs.io/en/1.4/installation.html
  2. Reinstall SQLParse (I had "sqlparse==0.2.3"): (found same bug here: https://github.com/jazzband/django-debug-toolbar/issues/856)
pip uninstall sqlparse

pip install sqlparse==0.9

And that's it. Not sure was it explicit setup or sqlparse reinstall, but now I do have debug_tool panel on FrontEnd and I do NOT want to touch anything! o_O I've spent almost three hours (yep, I'm rookie!) scrutinizing this crippy issue. And it's enough!

No thanx! Just help some other django rookie like me when he/she will need it.

Nathan Partridge
Nathan Partridge
52,420 Points

Thanks, your fix of installing the different version of sqlparse worked. However, I found that there was no 0.9 version, but there was a 0.1.9 in the list of available versions that pip returned. So I assumed that some how .1 was left out and installed 0.1.9 which works.

mykolash
mykolash
12,955 Points

Me personally, I guess yes.

But!

Not only this. DEBUG mode also should be disabled and many more stuff, I guess.

I think we need to ask @KennethLove to add such a course - "Deploying Django project live".

If you're interested - feel free to glance through DjangoGirls (you can notice its sticker on Kenneth's laptop) deploy chapter.

https://tutorial.djangogirls.org/en/deploy/

But, I would recommend you to pass it all from the very beginning - they use PythonAnywhere hosting service. It would take you few hours for all. Barely a day.

Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,320 Points

Thank you very much for the quick respond :-)

I'm still working on my first real project, but I just like to know in advance :-P Yeah it would be nice to have such a course "Deploying Django Project Live".

Douglas North
Douglas North
10,884 Points

I had a problem for ages but it's usually a silly human error. I was including it into my app urls file, not the main one xD Constantly learning from silly mistakes that cut away 20 minutes of your time.