Skip to content

Instantly share code, notes, and snippets.

@rcrowley
Created March 14, 2009 19:31
Show Gist options
  • Save rcrowley/79156 to your computer and use it in GitHub Desktop.
Save rcrowley/79156 to your computer and use it in GitHub Desktop.
Django Shell Script
#!/usr/bin/env python
"""
Django Shell Script
Richard Crowley <[email protected]>
I like organized directory structures. Because of the way the Python
path works, there wasn't a readily-available way to stash shell scripts
that needed access to Django goodness away in bin/. This is a bit
heavy on the scaffolding code (six lines, geez) but works.
"""
import os
import sys
sys.path[0] = os.path.normpath(os.path.join(sys.path[0], '..'))
from django.core.management import setup_environ
import settings
setup_environ(settings)
# Now you can import from your Django app!
# The proof is in the print()
if '__main__' == __name__:
print(dir(settings))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment