学习《python Web开发:测试驱动方法》坑点之一resolve('/')报错

在学习《Python Web开发:测试驱动方法》时遇到3.3.django单元测试部分的问题,测试root_url使用resolve('/')导致404错误。错误源于对resolve函数理解不准确,实际应检查'/home_page/'路径对应视图。修正后,测试通过。
摘要由CSDN通过智能技术生成

python Web开发:测试驱动方法---3.3.django中的单元测试,3.4MVC、URL和视图函数:

tests.py测试类中写的第一个单元测试函数,如下:
class HomePageTest(TestCase):
    def test_root_url_resolves_to_home_page_view(self):
        #print "befor exct found"
        found = resolve('/')
        #print "befor exct found:",found
        self.assertEqual(found.func, home_page)

执行后报404错误

Traceback (most recent call last):
  File "E:\djangoPreject\HelloWorld\cmdb\tests.py", line 11, in test_root_url_resolves_to_home_page_view
    found = resolve('/')
  File "C:\Python27\lib\site-packages\django\urls\base.py", line 27, in resolve
    return get_resolver(urlconf).resolve(path)
  File "C:\Python27\lib\site-packages\django\urls\resolvers.py", line 394, in resolve
    raise Resolver404({'tried': tried, 'path': new_path})
Resolver404: {u&#

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值