1

我有应用程序 app1。它已连接(通过INSTALLED_APPS)app2;假设 app2 对我来说是某种黑盒。但我知道它的网址中的 app2 有一些 i18n_patterns。
我需要包含从 app2 到我的 app1的所有url。并将它们包含在根位置:

urlpatterns = ('',
    (r'', include("app1.urls")),
    (r'', include("app2.urls")),
)

因为 app2.urls 中的 i18n_patterns 这样include在这里
ImproperlyConfigured('Using i18n_patterns in an included URLconf is not allowed.')
引发 源代码

有没有办法在不了解它们的情况下将所有 urlpatterns 附加app2.urls到 my urlpatterns

4

1 回答 1

5

For instance, you can from app2.urls import urlpatterns as urlpatterns2 and later in your urls.py at the end do this:

urlpatterns += urlpatterns2
# or maybe: 
# urlpatterns += urlpatterns2[1:] if you don't want to include the initial attribute

This behaves like a normal list concatenation and might work.

Note: This is a bit of hackery to overcome the include limitants. If there is a better way to do this I'll love to know.

Hope this helps!

于 2013-05-23T19:11:05.027 回答