Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django测试模块会产生这些错误_Python_Mysql_Django - Fatal编程技术网

Python Django测试模块会产生这些错误

Python Django测试模块会产生这些错误,python,mysql,django,Python,Mysql,Django,我刚到Django。我正在学习维托·弗雷塔斯的教程《Django的完整初学者指南》。在测试模块中,我得到如下所示的错误。你能告诉我我的错误吗 ERROR: test_redirection (boards.tests.test_view_reply_topic.SuccessfulReplyTopicTests) ---------------------------------------------------------------------- Traceback (most recen

我刚到Django。我正在学习维托·弗雷塔斯的教程《Django的完整初学者指南》。在测试模块中,我得到如下所示的错误。你能告诉我我的错误吗

ERROR: test_redirection (boards.tests.test_view_reply_topic.SuccessfulReplyTopicTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/hp/Desktop/PythonProjects/myproject/myproject/boards/tests/test_view_reply_topic.py", line 34, in test_redirection
    self.assertRedirects(self.response, topic_posts_url)
AttributeError: 'SuccessfulReplyTopicTests' object has no attribute 'response'
它引用的文件就是这个文件

class SuccessfulReplyTopicTests(ReplyTopicTestCase):

    def test_redirection(self):
        url = reverse('topic_posts', kwargs={'pk': self.board.pk, 'topic_pk': self.topic.pk})
        topic_posts_url = '{url}?page=1#2'.format(url=url)
        self.assertRedirects(self.response, topic_posts_url)
class SuccessfulSignUpTests(TestCase):

   def test_redirection(self):
         self.assertRedirects(self.response,self.home_url)
=====================================================

FAIL: test_redirection (accounts.tests.test_view_signup.SuccessfulSignUpTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/hp/Desktop/PythonProjects/myproject/myproject/accounts/tests/test_view_signup.py", line 62, in test_redirection
    self.assertRedirects(self.response, self.home_url)
  File "/usr/local/lib/python3.7/dist-packages/django/test/testcases.py", line 348, in assertRedirects
    % (response.status_code, status_code)
AssertionError: 200 != 302 : Response didn't redirect as expected: Response code was 200 (expected 302)
它引用的文件就是这个文件

class SuccessfulReplyTopicTests(ReplyTopicTestCase):

    def test_redirection(self):
        url = reverse('topic_posts', kwargs={'pk': self.board.pk, 'topic_pk': self.topic.pk})
        topic_posts_url = '{url}?page=1#2'.format(url=url)
        self.assertRedirects(self.response, topic_posts_url)
class SuccessfulSignUpTests(TestCase):

   def test_redirection(self):
         self.assertRedirects(self.response,self.home_url)
根据此处的代码:

1-您是否将此部分书写正确

class LoginRequiredPostUpdateViewTests(PostUpdateViewTestCase):
    def test_redirection(self):
        '''
        Test if only logged in users can edit the posts
        '''
        login_url = reverse('login')
        response = self.client.get(self.url)
        self.assertRedirects(response, '{login_url}?next={url}'.format(login_url=login_url, url=self.url))
2-很明显代码有很多错误,并且在帖子上有关于它的评论,你检查了所有的错误了吗

3-您在github中检查过代码吗? 祝你好运

根据此处的代码:

1-您是否将此部分书写正确

class LoginRequiredPostUpdateViewTests(PostUpdateViewTestCase):
    def test_redirection(self):
        '''
        Test if only logged in users can edit the posts
        '''
        login_url = reverse('login')
        response = self.client.get(self.url)
        self.assertRedirects(response, '{login_url}?next={url}'.format(login_url=login_url, url=self.url))
2-很明显代码有很多错误,并且在帖子上有关于它的评论,你检查了所有的错误了吗

3-您在github中检查过代码吗?
祝你好运

我仔细检查了代码。还检查了github。我可能错过了什么。我会再查的。谢谢你的尝试,你说的绝对正确。由于粗心大意,我漏掉了一大堆代码。现在它工作正常了。再次感谢。很乐意帮忙:)我仔细检查了代码。还检查了github。我可能错过了什么。我会再查的。谢谢你的尝试,你说的绝对正确。由于粗心大意,我漏掉了一大堆代码。现在它工作正常了。再次感谢。很乐意帮忙:)