我正在尝试按照此处所述应用 django URL 语言环境
https://docs.djangoproject.com/en/dev/topics/i18n/translation/#translating-url-patterns
下面是我的设置文件
LANGUAGE_CODE = 'en'
gettext = lambda s: s
LANGUAGES = (
('ar', gettext('Arabic')),
('en', gettext('English')),
)
我的 urls.py 如下
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.conf.urls.i18n import i18n_patterns
admin.autodiscover()
urlpatterns = patterns('',
url(r'^sitemap\.xml$', 'sitemap.view', name='sitemap_xml'),
)
urlpatterns += i18n_patterns('',
url(r'^', include('bon_app.apps.bonz.urls')),
url(r'^', include('bon_app.apps.pages.urls')),
)
它目前仅适用于英语,当我尝试 127.0.0.1/en/ 时它可以工作,但是当我尝试 127.0.0.1//ar/ 时,它不知道为什么会这样?
我目前使用 django 1.4
更新
bon_app/apps/bonz/urls.py
from django.conf.urls import patterns, include, url
urlpatterns = patterns('bon_app.apps.bonz.views',
url(r'^$', 'home', name='bonz-home'),
url(r'^promotion/$', 'home', {'model' : 'Promotion'}, name='bonz-promo'),
url(r'^event/$', 'home', {'model' : 'Event'}, name='bonz-event'),
url(r'^directory/$', 'directory', name='bonz-directory')
)
bon_app/apps/pages/urls.py
from django.conf.urls import patterns, include, url
urlpatterns = patterns('bon_app.apps.pages.views',
url(r'^contact-us/$', 'contact_us', name='pages-contactus'),
url(r'^about-us/$', 'about_us', name='pages-aboutus'),
)