In my previous post I talk about the reusable apps, but I don ' t really explain it's that much. If you have a app that might is useful in another project, it's best to not refer to the project name in the application So you don ' t has to search and remove it when adding to another project. To never refer to your project name in your app's code, you'll need to put your app on the Python path. I usually doproject_folder/apps/app_folder so apps would need to being a location this python is checking wh En you is importing so this importing looks like the following:
From Appname.filename import foo
There is a few places you might need to add an Apps folder to the Pythonpath.
Add to settings.py
This would add the apps directory in your project directory to the beginning of the path list. This would allow manage.py syncdb and manage.py runserver to know that the Apps folder should be added.
Import OS import sys project_root = Os.path.dirname (__file__) sys.path.insert (0, Os.path.join (project_root, "apps"))
That should is all need to does to get the most Django projects working with your reusable apps and if for any reason you n Eed add to the path with mod python or mod wsgi, the following should work.
Apache Mod_python
in the setting-up-everything post I Show an example httpd.conf file. In your Apache configuration you'll probably see something similar to what's below. To add, /var/www/myproject/apps to the PythonPath I added it In the list.
SetHandler Python-programpythonhandler DJANGO.CORE.HANDLERS.MODPYTHONSETENV Django_settings_module Myproject.settingspythonoption django.root/myprojectpythondebug Onpythonpath "['/var/www ', '/var/www/myproject/ Apps '] + Sys.path "
Apache Mod_wsgi
If you use mod wsgi instead of mod python, your Apache config would be loading a WSGI file with a line like this C1>wsgiscriptalias/var/www/myproject/myproject.wsgi. You'll need to edit this file to add to the path (Django's site has a example file).
Sys.path.append ('/var/www/myproject/apps ')
You never know if you might want-to-use a app in another project, so always try-to-keep from mentioning the project Nam e anywhere in the applications.
How to Add Locations to Python Path for reusable D