0

Lets say we have a page:

http://www.example.com/cs/department/category/

I am using django-locale for internationalization.

How am I going to achieve that if somebody type:

http://www.example.com/en/department/category/

EN instead of CS it will redirect.

I achieve this by commenting out the other languages like this:

enter image description here

But what I would like to do is keep them there uncommented. What would be the proper redirect in urls.py or views.py that only 'CS' is working. DE & EN would be redirected. If you dont understand I can clarify more.

Thanks

Radek
  • 1,149
  • 2
  • 19
  • 40

1 Answers1

0

Fast and lazy solution can be:

views.py

from django.http import HttpResponseRedirect

def myview(request):
    newurl = 'define your new url here'
    if not 'cs/' in request.get_full_path():
        return HttpResponseRedirect(newurl)
Goran
  • 6,644
  • 11
  • 34
  • 54
  • But if I have lets say 20 views, I have to add it to every single one of them? – Radek Oct 16 '13 at 23:31
  • Yes in this case but you can also create redirect in urls.py ` from django.views.generic import RedirectView ` then in your urlpatterns add ` url(r'^bad_url/$', RedirectView.as_view(url= 'good_url')), ` hope it helps – Goran Oct 17 '13 at 12:42