KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am using debug toolbar with django and would like to add it to project if two conditions are true: settings.DEBUG is True module itself exists It's not hard to do the first one # adding django debug toolbar if DEBUG: MIDDLEWARE_CLASSES += 'debug_toolbar.middleware.DebugToolbarMiddleware', INSTALLED_APPS += 'debug_toolbar', But how do I check if module exists? I have found this solution: try: import debug_toolbar except ImportError: pass But since import happens somewhere else in django, I need if/else logic to check if module exists, so I can check it in settings.py def module_exists(module_name): # ?????? # adding django debug toolbar if DEBUG and module_exists('debug_toolbar'): MIDDLEWARE_CLASSES += 'debug_toolbar.middleware.DebugToolbarMiddleware', INSTALLED_APPS += 'debug_toolbar', Is there a way to do it?
Tags (comma-separated)
Save Edits
Cancel