Skip to content

Commit 4b01ee7

Browse files
committed
URL-encoded URLs in FlatPage.get_absolute_url.
1 parent e4ee3d8 commit 4b01ee7

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

django/contrib/flatpages/models.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
from django.db import models
44
from django.contrib.sites.models import Site
55
from django.utils.translation import ugettext_lazy as _
6-
from django.utils.encoding import python_2_unicode_compatible
7-
6+
from django.utils.encoding import iri_to_uri, python_2_unicode_compatible
87

98
@python_2_unicode_compatible
109
class FlatPage(models.Model):
@@ -27,4 +26,4 @@ def __str__(self):
2726
return "%s -- %s" % (self.url, self.title)
2827

2928
def get_absolute_url(self):
30-
return self.url
29+
return iri_to_uri(self.url)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from django.contrib.flatpages.tests.csrf import *
22
from django.contrib.flatpages.tests.forms import *
3+
from django.contrib.flatpages.tests.models import *
34
from django.contrib.flatpages.tests.middleware import *
45
from django.contrib.flatpages.tests.templatetags import *
56
from django.contrib.flatpages.tests.views import *
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# coding: utf-8
2+
3+
from __future__ import unicode_literals
4+
5+
from django.contrib.flatpages.models import FlatPage
6+
from django.test import TestCase
7+
8+
9+
class FlatpageModelTests(TestCase):
10+
11+
def test_get_absolute_url_urlencodes(self):
12+
pf = FlatPage(title="Café!", url='/café/')
13+
self.assertEqual(pf.get_absolute_url(), '/caf%C3%A9/')
14+
15+

0 commit comments

Comments
 (0)