上QQ阅读APP看书,第一时间看更新
How to do it...
Execute the following steps one by one for a virtual environment project:
- If you haven't done so already, create an externals directory under your Django project django-myproject directory. Then, create the libs and apps directories under it. The libs directory is for the Python modules that are required by your project, for example, Boto, Requests, Twython, and Whoosh. The apps directory is for third-party Django apps, for example, Django CMS, Django Haystack, and django-storages.
We highly recommend that you create README.md files in the libs and apps directories, where you mention what each module is for, what the used version or revision is, and where it is taken from.
- The directory structure should look something similar to the following:
externals/
├── apps/
│ ├── cms/
│ ├── haystack/
│ ├── storages/
│ └── README.md
└── libs/
├── boto/
├── requests/
├── twython/
└── README.md
- The next step is to put the external libraries and apps under the Python path so that they are recognized as if they were installed. This can be done by adding the following code in the settings:
# settings.py
import os, sys
BASE_DIR = os.path.dirname(os.path.dirname(
os.path.abspath(__file__)))
EXTERNAL_BASE = os.path.join(BASE_DIR, "externals")
EXTERNAL_LIBS_PATH = os.path.join(EXTERNAL_BASE, "libs")
EXTERNAL_APPS_PATH = os.path.join(EXTERNAL_BASE, "apps")
sys.path = ["", EXTERNAL_LIBS_PATH, EXTERNAL_APPS_PATH] + sys.path