Issue trying to change language from Django template

前端 未结 7 2162
悲&欢浪女
悲&欢浪女 2020-12-01 06:46

I need to include two buttons or links to allow users change language between English and Spanish. I\'ve read the docs and tried this:

7条回答
  •  南笙
    南笙 (楼主)
    2020-12-01 07:46

    A sum-up of possible options:

    Change the user's session language with a select

    There is an excellent extensive description with example on Django docs.

    Change the user's session language with buttons

    There is no need to repeat a form for each button as @Caumons suggested, instead you can simply include as many buttons in the form as the languages.

    
        {% csrf_token %}
        
        
    
    

    You can certainly style up the buttons to look like links or whatever.

    Change the language displayed with links

    If it is not required that the default user session language is changed, then simple links can be used to change the content:

    
    

    SEO

    I am not entirely sure that the content is seo friendly if a form is used to change the session language, as Django recommends. Therefore it is possible that the link markup is added as hidden below the

提交回复
热议问题