【发布时间】:2021-09-02 15:09:25
【问题描述】:
当运行开发服务器(py manage.py runserver)和用户浏览器的url“localhost:8000//index.html”时,它给出404。
但在运行测试时,client.get('//index.html') 为200,内容与对('/') 的请求相同。
运行开发服务器时,使用py manage.py shell,然后从django.test import Client,直接运行也是一样的结果。
这是 Client.get() 函数的问题吗?还是我用错了?
def test_invalid_url2(self):
response=self.client.get('//index.html')
self.assertEqual(response.status_code, 404)
【问题讨论】:
-
测试过的网址有效,可以接受多个斜杠。例如试试这个 URL:stackoverflow.com////questions/69032876/…