/ Published in: Python
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
# This snippet is useful when you want to use a django project which runs in a Python virtual environment. """ This code should be executed before the imports you need from your django project For example, you can place it at the end of your settings.py """ import sys, os # Add the directory containing your django project 'myproj' to the path sys.path.insert(0, '/django-projs/') # Set the django settings environment variable os.environ['DJANGO_SETTINGS_MODULE'] = 'myproj.settings' # Activate the virtual environment used in the django project execfile('/path/to/virtual/env/bin/activate_this.py', {'__file__': '/path/to/virtual/env/bin/activate_this.py'}) # Now you can import any model, for example from myproj.myapp.models import MyModel # Snippet imported from snippets.scrapy.org (which no longer works) # author: anibal # date : Aug 16, 2010