django.test.TestCase AtrributeError:' str'对象没有属性' get'

时间:2015-05-16 04:29:17

标签: python django unit-testing python-3.x

在尝试按照this教程运行单元测试时出现上述错误。

包含单元测试的类如下:

# -*- coding: utf-8 -*-
from django.test import TestCase
from django.core.urlresolvers import reverse


class TestHomePage(TestCase):

    def test_uses_index_template(self):
        response = self.client.get(reverse("home"))
        self.assertTemplateUsed(response, "taskbuster/index.html")

    def test_uses_base_template(self):
        response = self.client.get(reverse("home"))
        self.assertTemplateUsed(response, "base.html")

调用self.client.get()方法时会抛出错误。

帮助将不胜感激。

引发的回溯:

Traceback (most recent call last):
  File "/Users/bIgB/Programming/languages/python/taskbuster_project /taskbuster/test.py", line 9, in test_uses_index_template
response = self.client.get(reverse("home"))
  File "/Users/bIgB/.virtualenvs/tb_test/lib/python3.4/site-packages/django/test/client.py", line 500, in get
**extra)
  File "/Users/bIgB/.virtualenvs/tb_test/lib/python3.4/site-packages/django/test/client.py", line 303, in get
return self.generic('GET', path, secure=secure, **r)
  File "/Users/bIgB/.virtualenvs/tb_test/lib/python3.4/site-packages/django/test/client.py", line 379, in generic
return self.request(**r)
  File "/Users/bIgB/.virtualenvs/tb_test/lib/python3.4/site-packages/django/test/client.py", line 466, in request
six.reraise(*exc_info)
  File "/Users/bIgB/.virtualenvs/tb_test/lib/python3.4/site-packages/django/utils/six.py", line 659, in reraise
raise value
  File "/Users/bIgB/.virtualenvs/tb_test/lib/python3.4/site-packages/django/core/handlers/base.py", line 223, in get_response
response = middleware_method(request, response)
  File "/Users/bIgB/.virtualenvs/tb_test/lib/python3.4/site-packages/django/middleware/clickjacking.py", line 31, in process_response
if response.get('X-Frame-Options', None) is not None:

属性错误:' str'对象没有属性' get'

0 个答案:

没有答案