Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
430 views
in Technique[技术] by (71.8m points)

multilingual - How to remove the language identifier from django-cms 2.4 URLs?

I have followed the tutorial to make a new Django-CMS (2.4) site. I am only using a single language (English).

There is an automatic redirect to include the language identifier '/en/' in my site's URLs. How do I remove it?

thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Option 1:

Set USE_I18N = False in your settings file.

Django’s internationalization hooks are on by default... If you don’t use internationalization, you should take the two seconds to set USE_I18N = False in your settings file. [Django documentation:Translation]

The internationalization is "inherited" from Django. Django-cms 2.4 uses Django 1.5 which supports internationalization and the use of USE_I18N flag. The flag has been used in all successive django releases.

Option 2:

replace this pattern registration:

urlpatterns = i18n_patterns('',
 url(r'^admin/', include(admin.site.urls)),
 url(r'^', include('cms.urls')),
)

with this:

from django.conf.urls import patterns

urlpatterns = patterns('',
  url(r'^admin/', include(admin.site.urls)),
  url(r'^', include('cms.urls')),
)

The tutorial you pointed to uses the i18n_patterns method which does exactly this: prepends the language code to your urls.

Also note you can safely remove 'django.middleware.locale.LocaleMiddleware' and 'cms.middleware.language.LanguageCookieMiddleware' from your MIDDLEWARE_CLASSES if you will not use multiple languages.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...