(実行時に) 動的モジュールをロードする必要がある Django アプリケーションを開発しています。これで、(クライアント ブラウザーからサーバーに) "プラグイン" をアップロードし、プラグイン モデルをデータベースに登録することができます。ただし、各プラグインの urlpatterns を処理する方法が必要です。現在、モデルを登録し、(理論的には) アップロードされたプラグインの urlpatterns を webapp urls.py に追加する関数を webapp の「コア」に記述しました。この関数は次のとおりです。
def register_plugin_model(model,codename):
# Standard syncdb expects models to be in reliable locations,
# so dynamic models need to bypass django.core.management.syncdb.
# On the plus side, this allows individual models to be installed
# without installing the entire project structure.
# On the other hand, this means that things like relationships and
# indexes will have to be handled manually.
# This installs only the basic table definition.
if model is not None:
style = color.no_style()
cursor = connection.cursor()
tables = connection.introspection.table_names()
seen_models = connection.introspection.installed_models(tables)
statements,trsh = connection.creation.sql_create_model(model, style, seen_models)
for sql in statements:
cursor.execute(sql)
# add urlpatterns
from django.conf.urls.defaults import patterns, url,include
from project.plugins.urls import urlpatterns
urlpatterns += patterns(url(r'^' + codename + '/' , include ( 'media.plugins.' + codename + '.urls' )))
プラグインは tgz 形式で「media/tmp」にアップロードされ、「media/plugins/」に抽出されます。ここで、 はプラグインのコードネームであり、ユーザーがアップロードしたプラグインは「project.plugins」によって管理されます。
すべてのプラグイン ロジックは正常に動作しますが、アップロードされたプラグイン urls.py ファイルを webapp (project.plugins.urls) に含めようとすると、効果がありません。「project.plugins.urls.urlpatterns」の値を出力しましたが、「urlpatterns += pat....」の後に変更されていません。
必要なことを行う方法はありますか?
よろしくお願いします