Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #18700 -- Added URL reversal for i18n set_language view.

  • Loading branch information...
commit 10f979fd92000de1ac9713351f5cb749e2cbca03 1 parent b496be3
Simon Meers authored
4  django/conf/urls/i18n.py
... ...
@@ -1,5 +1,5 @@
1 1
 from django.conf import settings
2  
-from django.conf.urls import patterns
  2
+from django.conf.urls import patterns, url
3 3
 from django.core.urlresolvers import LocaleRegexURLResolver
4 4
 
5 5
 def i18n_patterns(prefix, *args):
@@ -16,5 +16,5 @@ def i18n_patterns(prefix, *args):
16 16
 
17 17
 
18 18
 urlpatterns = patterns('',
19  
-    (r'^setlang/$', 'django.views.i18n.set_language'),
  19
+    url(r'^setlang/$', 'django.views.i18n.set_language', name='set_language'),
20 20
 )
2  docs/topics/i18n/translation.txt
@@ -1272,7 +1272,7 @@ Here's example HTML template code:
1272 1272
 
1273 1273
 .. code-block:: html+django
1274 1274
 
1275  
-    <form action="/i18n/setlang/" method="post">
  1275
+    <form action="{% url 'set_language' %}" method="post">
1276 1276
     {% csrf_token %}
1277 1277
     <input name="next" type="hidden" value="{{ redirect_to }}" />
1278 1278
     <select name="language">
4  tests/regressiontests/views/tests/i18n.py
@@ -5,6 +5,7 @@
5 5
 from os import path
6 6
 
7 7
 from django.conf import settings
  8
+from django.core.urlresolvers import reverse
8 9
 from django.test import TestCase
9 10
 from django.utils.translation import override, activate, get_language
10 11
 from django.utils.text import javascript_quote
@@ -23,6 +24,9 @@ def test_setlang(self):
23 24
             self.assertRedirects(response, 'http://testserver/views/')
24 25
             self.assertEqual(self.client.session['django_language'], lang_code)
25 26
 
  27
+    def test_setlang_reversal(self):
  28
+        self.assertEqual(reverse('set_language'), '/views/i18n/setlang/')
  29
+
26 30
     def test_jsi18n(self):
27 31
         """The javascript_catalog can be deployed with language settings"""
28 32
         saved_lang = get_language()

0 notes on commit 10f979f

Please sign in to comment.
Something went wrong with that request. Please try again.