동적 모듈을로드해야하는 Django 응용 프로그램을 개발 중입니다 (런타임에). 이제 (클라이언트 브라우저에서 서버로) "플러그인"을 업로드하고 데이터베이스에 플러그인 모델을 등록 할 수 있습니다. 그러나 각 플러그인의 url 패턴을 처리 할 방법이 필요합니다. 현재 모델을 등록하고 (이론적으로) 업로드 된 플러그인의 url 패턴을 webapp urls.py에 포함시킴으로써 모델을 등록하는 webapp의 "코어"에 함수를 작성했습니다. 이 함수는 다음Django에서 런타임에 urlpattern을 수정합니다.
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 형식 "미디어/TMP"에 업로드되고이 "미디어/플러그인 /"어디 플러그인의 코드 명이고, 사용자 업로드 플러그인에 의해 관리되는 " project.plugins "를 참조하십시오.
모든 플러그인 로직이 잘 작동하지만 업로드 된 플러그인 urls.py 파일을 webapp (project.plugins.urls)에 포함 시키려고해도 효과가 없습니다. "project.plugins.urls.urlpatterns"의 값을 인쇄했으며 "urlpatterns + = pat ...."다음에 수정되지 않았습니다.
내가 할 수있는 방법이 있습니까?
안부