Snippet List
Add this code to the end of the `<body>` of your main template and it will print out all your SQL queries with timings in the Firebug console.
This uses the "django.core.context_processors.debug" template context processor, which requires that DEBUG=True and that your IP address is listed in INTERNAL_IPS.
- sql
- debug
- console
- firebug
- sql_queries
When running the Django development server, this middleware causes all executed SQL queries to get printed out to the console.
This is based on [Snippet 161](http://www.djangosnippets.org/snippets/161/). The big difference is that 161 logs by adding stuff to your response text, which isn't very convenient IMO.
- sql
- middleware
- log
- debug
- logging
- console
Put this in an __init__.py somewhere that will be executed on initialization and all errors will be printed out to stderr. Useful for debugging Facebook apps, javascript calls, etc.
- print
- console
- exception
- signal
The django debug screens are great, but only when you can see them. Trying to debug javascript/ajax calls can be kind of a pain. This just a copy/paste of some code in django's internals stuck in a middleware so that exceptions also print to the dev server console.
- middleware
- console
- exception
Call this function as the first thing in your cron, or console script; it will bootstrap Django, and allow you to access all of the Django modules from the console, with out using 'python manage.py shell'
Examples:
# A script within your django project.
from django_bootstrap import bootstrap
bootstrap(__file__)
--- or ---
# A cron script located outside of your django project
from django_bootstrap import bootstrap
bootstrap("/path/to/your/project/root/")
- django
- console
- cron
- bootstrap
Just put it in your python path and add it into MIDDLEWARE_CLASSES.
I know that there are a couple of snippets on this site that do something similar to this, but none of them quite suited me.
I wanted something that would indent and space the SQL so that I could differentiate it from the other output from the development server.
Also, I wanted something that would output total query execution time, which my solution does. I just hope that it's useful for someone else, too!
UPDATE: Now this should no longer get upset when running it on windows.
- sql
- middleware
- profile
- debug
- help
- console
- printing
- speed
when running a console script to access django or your models, you need to setup django environment properly and that is very annoying if you have quite a few scripts. this script can be used as a wrapper just like the manage.py.
put it in your project root and type this:
python run.py myproj.appname.filename.functionname [arguments]
and define your function as
def functionname(argv[]):
...
7 snippets posted so far.