Can I redirect to another url in a django TemplateView?

后端 未结 4 2073
盖世英雄少女心
盖世英雄少女心 2021-02-02 09:13

I have a url mapping that looks like this:

url(r\'^(?P[a-z][a-z])/$\', MyTemplateView.as_view()),

There are only a few values that

4条回答
  •  鱼传尺愫
    2021-02-02 09:59

    Why only get_context_data?

    Just set up your get handler to do a redirect if necessary.

    def get(self, request, lang):
        if lang == 'fr':
             return http.HttpResponseRedirect('../en')
    
         return super(MyTemplateView, self).get(request, lang)
    

提交回复
热议问题