摆脱' en-us'在Django网址i18n

时间:2017-05-11 19:57:24

标签: django url internationalization

使用 Django 1.8.17

我的谷歌统计数据中有很多404。这是因为有些网址的格式如下:

  

http://www.example.com/en-us/some_content_here

我无法想象如何摆脱这些en-us lang,在这种情况下最好用en替换。

以下是我的i18n设置:

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en'

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True

LANGUAGES = (('de', gettext('German')),
             ('en', gettext('English')),
             ('es', gettext('Spanish')),
             ('it', gettext('Italian')),
             ('fr', gettext('French')),
             ('ru', gettext('Russian')),
             ('ja', gettext('Japanese')),
             ('pt', gettext('Portuguese')),)

如果没有匹配,有没有办法重定向到相应的语言,默认为en?

1 个答案:

答案 0 :(得分:0)

当您使用django 1.8时,请查看this answer

如果您可以升级到django当前版本(或至少1.10),您将获得原生支持,请查看docs