下面有详细信息,但是有人可以告诉我这正在发生。
class UserDashboardView(View):
def get(self, request, *args, **kwargs):
return HttpResponseRedirect('/accounts/login')
我的测试用例
import unittest
from django.test import TestCase
class DashboardPageTest(TestCase):
def test_unauthenticated_user_redirected_to_login(self):
response = self.client.get('/dashboard')
print(response)
发生了什么。
1-如果我在Chrome和Firefox中转到/ dashboard,则调试会显示302,其位置密钥为/ accounts / login,因此浏览器会转到/ accounts / login
2-如果我运行单元测试(python manage.py测试),则响应的打印返回
<HttpResponsePermanentRedirect status_code=301, "text/html; charset=utf-8", url="/dashboard/">
我感觉他们只是浏览器与TestCase重定向的方式而已。有人可以解释一下吗?
[尝试进行一个项目,使我的头脑转向单元测试。我很困惑为什么client.get得到的重定向不同于Firefox和Chrome。详细信息在下面,但是有人可以给我...
/dashboard
重定向到/dashboard/
。[基本上,Django很有帮助,并在请求末尾添加了/。因此,它发送回永久重定向以通知我。 Chrome和Firefox应该已经解决了将测试用例中的行更改为