私は何が欠けているのかを理解しようとして、すでに数時間を費やしてきました。プロジェクト設定ファイルで言語を定義しています。
LANGUAGE_CODE = 'en-us'
LANGUAGES = (
('en', 'English'),
('fr', 'French'),
)
次に、LocaleMiddleware を MIDDLEWARE_CLASSES にリストします。
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
...
)
そして最後に私の urls.py には次のものがあります
from django.conf.urls import patterns, include, url
from django.conf.urls.i18n import i18n_patterns
...
urlpatterns += i18n_patterns('',
url(r'^about/$', 'about.view', {'template_name': {'en':'contact_en.html', 'fr':'contact_fr.html',},}, name='about'),
)
リンク /en/about は正常に機能するようになりましたが、/fr/about を含むリンクは次のエラーで失敗します。
Using the URLconf defined in XXX.urls, Django tried these URL patterns, in this order:
...
2. ^en/
The current URL, fr/about/, didn't match any of these.
私が欠けているものを理解するのを手伝ってくれる人はいますか?