测试 Django url 'name' 是否正确 url
Test Django url 'name' is correct url
我认为我正在尝试的是不言而喻的:
urls.py
urlpatterns = [
path('', views.home_page, name='home_page'),
]
test.py
def test_home_page_view_name_uses_correct_url(self):
name = self.client.get(reverse('home_page'))
path = self.client.get('/')
self.assertEqual(name, path)
但是我得到这个错误:
AssertionError: <HttpResponse status_code=200, "text/html; charset=utf-8">
!= <HttpResponse status_code=200, "text/html; charset=utf-8">
我怎样才能正确测试它?
似乎没有任何理由让客户参与进来。
name = reverse('home_page')
path = '/'
self.assertEqual(名称,路径)
我认为我正在尝试的是不言而喻的:
urls.py
urlpatterns = [
path('', views.home_page, name='home_page'),
]
test.py
def test_home_page_view_name_uses_correct_url(self):
name = self.client.get(reverse('home_page'))
path = self.client.get('/')
self.assertEqual(name, path)
但是我得到这个错误:
AssertionError: <HttpResponse status_code=200, "text/html; charset=utf-8">
!= <HttpResponse status_code=200, "text/html; charset=utf-8">
我怎样才能正确测试它?
似乎没有任何理由让客户参与进来。
name = reverse('home_page')
path = '/'
self.assertEqual(名称,路径)