0

I have following structure of my folders in Django:

./project_root
    ./app
       ./fixtures/
       ./static/
       ./templates/
       ./blog/
       ./settings.py
       ./urls.py
       ./views.py
       ./manage.py
       ./__init__.py 
    ./plugin
       ./code_editor
           ./static
           ./templates
           ./urls.py
           ./views.py
           ./__init__.py 
       ./code_viewer
           ./static
           ./templates
           ./urls.py
           ./views.py
           ./__init__.py 

So how I can change settings.py in order to load plugins dynamically (It means i do not know how many plugins will be installed in different servers. It should dynamically check it on run time and add it.)on:

python manage.py runserver

Shoule i change ROOT_URLSCONF? or INSTALLED_APPS? Thank you for answers.

Khamidulla
  • 2,927
  • 6
  • 35
  • 59
  • you need to add the apps/plugin to `INSTALLED_APPS` and you need to include the apps urls in the `urls.py` in project directory. –  Nov 07 '13 at 02:25
  • @void Is it possible to make it dynamically? I now that I can manually. What about adding to ROOT_URLCONF and give it several values? – Khamidulla Nov 07 '13 at 02:29

1 Answers1

1

Have your settings.py execute code to determine which plugins exist by scanning the 'plugin' folder, and build up the appropriate INSTALLED_APPS variable.

# In settings.py    
for path in os.listdir(my_plugins_folder_location):
    if os.path.isdir(path):
        app_name = 'project_root.plugin.%s' % path
        if app_name not in INSTALLED_APPS:
            INSTALLED_APPS.append(app_name)
Austin Phillips
  • 15,228
  • 2
  • 51
  • 50