urls.py
from django.conf.urls import patterns, include, url from django.conf.urls.i18n import i18n_patterns from django.utils.translation import ugettext_lazy as _ from django.contrib import admin admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^i18n/', include('django.conf.urls.i18n')), )
urlpatterns += i18n_patterns('',
(_(r'^dual-lang/'), include('duallang.urls')),
(r'^', include('home.urls')), )
from django.conf import settings
if 'rosetta' in settings.INSTALLED_APPS:
urlpatterns += patterns('',
url(r'^rosetta/', include('rosetta.urls')),
)
获取ImportError:无法从中导入名称“模式” 'django.conf.urls'
答案 0 :(得分:0)
您必须将模式转换为列表,可以将url伪装成路径或re_path,如下所示:
from django.urls import path, include
urlpatterns = [
path('admin/', include(admin.site.urls)),
path('i18n/', include('django.conf.urls.i18n'))
]
i18n_pattern可以这样使用:
from django.conf.urls.i18n import i18n_patterns
from django.urls import path, include
urlpatterns += i18n_patterns(
path('', include('home.urls'))
)