Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save manjurulhoque/62a2961b2d648298e4fdd9f9e2f9f16b to your computer and use it in GitHub Desktop.

Select an option

Save manjurulhoque/62a2961b2d648298e4fdd9f9e2f9f16b to your computer and use it in GitHub Desktop.
Run python script from django shell
For python3 you would need to use
>>> exec(open('myscript.py').read())
or
import os, django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")
django.setup()
# now your code can go here...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment