您想要的是这样的东西:
from django.utils.importlib import import_modulefor app in settings.INSTALLED_APPS: try: mod = import_module('%s.urls' % app) # possibly cleanup the after the imported module? # might fuss up the `include(...)` or leave a polluted namespace except: # cleanup after module import if fails, # maybe you can let the `include(...)` report failures pass else: urlpatterns += patterns('', url(r'^%s/' % slugify(app), include('%s.urls' % app) )您还将想要
slugify从django模板或utils中窃取并实现自己的工具(我现在不太确定它们现在在哪里吗?),并对其稍加修改以去除任何“点”和其他不需要的命名空间在您的“网址”中,例如,您可能不希望自己的网址看起来像这样:“
example.com/plugin.some_plugin_appname/”,但喜欢
example.com/nice_looking_appname/
您甚至可能根本不想为其自动命名,而是在插件自己的“设置”模块中进行可配置的“设置”或类似的操作:
# plugin settings confurl_namespace = 'my_nice_plugin_url/'# root urls.py:url(r'^%s/' % mod.url_namespace, include(...))# or:url(r'^%s/' % app.settings.url_namespace, inc..
您可能会明白要点。
亲切的问候,



