Tools for Development and Debugging in Python
- 1. DISQUS
Tools and Stu
David Cramer
twitter.com/zeeg
Friday, July 15, 2011
- 3. $ pip install django-debug-toolbar
# settings.py
INSTALLED_APPS = (
'debug_toolbar',
)
MIDDLEWARE_CLASSES = (
'debug_toolbar.middleware.DebugToolbarMiddleware',
)
INTERNAL_IPS = ('127.0.0.1',)
Friday, July 15, 2011
- 8. Extending the Toolbar
class SettingsVarsDebugPanel(DebugPanel):
"""
A panel to display all variables in django.conf.settings
"""
name = 'SettingsVars'
has_content = True
def nav_title(self):
return _('Settings')
def title(self):
return _('Settings')
def content(self):
context = self.context.copy()
context.update({
'settings': get_safe_settings(),
})
return as_string('debug_toolbar/panels/settings.html', context)
Friday, July 15, 2011
- 9. Extending the Toolbar
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',
)
Friday, July 15, 2011
- 10. Werkzeug
w/ django-devserver
Friday, July 15, 2011
- 11. $ pip install django-devserver
# settings.py
INSTALLED_APPS = (
'devserver',
)
$ python manage.py runserver
Friday, July 15, 2011
- 14. • SQL Queries (Realtime and Summarized)
• Profiling (Execution time, Memory Usage)
• Cache usage summary
• Ajax requests
• Session information
• Write your own!
Friday, July 15, 2011
- 15. class AjaxDumpModule(DevServerModule):
"""
Dumps the content of all AJAX responses.
"""
logger_name = 'ajax'
def process_response(self, request, response):
if request.is_ajax():
self.logger.info(response.content)
Friday, July 15, 2011
- 16. Extending the Toolbar
DEVSERVER_MODULES = (
'devserver.modules.sql.SQLSummaryModule',
'devserver.modules.ajax.AjaxDumpModule’,
'devserver.modules.profile.ProfileSummaryModule',
'devserver.modules.request.SessionInfoModule',
'devserver.modules.profile.MemoryUseModule',
'devserver.modules.profile.LeftOversModule',
'devserver.modules.cache.CacheSummaryModule',
)
Friday, July 15, 2011
- 18. $ pip install django-sentry
# settings.py
INSTALLED_APPS = (
'sentry',
'sentry.client',
)
Friday, July 15, 2011
- 21. # settings.py
MIDDLEWARE_CLASSES = (
'sentry.client.middleware.SentryResponseErrorIdMiddleware',
)
# 500.html
<p>Sorry friends, something’s not working.</p>
{% if request.sentry.id %}
<p>If you need assistance, you may reference this error
as <strong>{{ request.sentry.id }}</strong>.</p>
{% endif %}
Friday, July 15, 2011
- 23. • Builtin support for Celery
• Server/Client (clients can be any language)
• 2.x powered by Flask/Redis (no Django)
Friday, July 15, 2011
- 25. $ pip install gargoyle
# settings.py
INSTALLED_APPS = (
'gargoyle',
)
Friday, July 15, 2011
- 27. from gargoyle import gargoyle
def my_view(request):
if gargoyle.is_active('awesome', request):
return 'new happy version :D'
else:
return 'old sad version :('
Friday, July 15, 2011
- 28. class HostConditionSet(ConditionSet):
hostname = String()
def can_execute(self, instance):
return instance is None
def get_field_value(self, instance, field_name):
if field_name == 'hostname':
return socket.gethostname()
gargoyle.register(HostConditionSet())
Friday, July 15, 2011
- 31. DISQUS
Questions?
psst, we’re hiring
jobs@disqus.com
Friday, July 15, 2011
- 32. References
• Debug Toolbar
https://github.com/django-debug-toolbar/django-debug-toolbar
• Devserver
https://github.com/dcramer/django-devserver
• Werkzeug
https://github.com/mitsuhiko/werkzeug
• Gargoyle
https://github.com/disqus/gargoyle
• Sentry
https://github.com/dcramer/django-sentry (1.x)
https://github.com/dcramer/sentry (2.x)
code.disqus.com
Friday, July 15, 2011