我正在开发需要加载动态模块(在运行时)的Django应用程序。现在,我可以上载(从客户端浏览器到服务器)“插件”并在数据库中注册插件模型,等等。但是我需要一种方法来处理每个插件的urlpatterns。当前,我已经在webapp的“核心”中编写了一个函数,该函数注册了一个模型,并(通过理论上)通过包含该插件将上传插件的urlpatterns添加到了webapp urls.py中。该函数是:
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() …Run Code Online (Sandbox Code Playgroud)