爲什麼這兩個斷言工作:爲什麼assertRedirects()期望一個字符串而不是一個URL?
from django.test import TestCase
class MyTests(TestCase):
def test_1(self):
response = self.client.get(reverse_lazy('create_cm'))
self.assertRedirects(response, reverse('upload_booth'))
self.assertRedirects(response, str(reverse_lazy('upload_booth')))
但這並不:
self.assertRedirects(response, reverse_lazy('upload_booth'))
而不是產生此錯誤消息:
File "/usr/local/lib/python2.7/dist-packages/django/test/testcases.py", line 300, in assertRedirects e_query, e_fragment))
File "/usr/lib/python2.7/urlparse.py", line 234, in urlunsplit url = '//' + (netloc or '') + url TypeError: coercing to Unicode: need string or buffer, proxy found
究竟是返回值的差異來自reverse和reverse_lazy,以及它們爲什麼不同?