问题描述
我试图在我的tests.py中创建一个测试
I tried to create a test in my tests.py
class TaskViewTests(TestCase):
def test_task_view_with_no_task(self):
"""
If no task exist, an appropriate message should be displayed.
"""
userName = 'esutek'
response = self.client.get(reverse('actuser:task',args=(userName,)))
self.assertEqual(response.status_code, 200)
self.assertContains(response, "No task are available.")
self.assertQuerysetEqual(response.context['taskList'], [])
但是它给我这个错误信息。
我没有任何线索为什么会发生这种情况。我刚刚遵循这个教程。
However it gives me this error message.I don't have any clue why this happened. I just followed the tutorial.
actuser:task
views.py
actuser:taskviews.py
def task(request, userName):
""" User task list in actInbox
"""
user = ActuserViewModel()
user.get_task_list(userName)
return render(request, 'actuser/task.html', {
'userName': userName,
'taskList': user.taskList,
'dateToday': user.dateToday,
})
viewmodels.py
viewmodels.py
def get_task_list(self, userName):
self.taskList = Task.objects.filter(executor = userName, parent_task_id=EMPTY_UUID).order_by('due_date')
#get date now with this format 05/11
self.dateToday = datetime.date.today()
其实我有2个网址...
Actually I got 2 urls...
这是从项目
url(r'^(?P<userName>[0-9a-zA-Z--]+)/', include('actuser.urls', namespace="actuser")),
actuser.urls
and this one is from actuser.urls
url(r'^task/$', views.task, name='task'),
推荐答案
表示您被重定向到其他URL。如果您使用,或者如果您忘记在请求URL的末尾写斜线,并且您有启用(在这种情况下,您将获得HTTP 301而不是302)。
HTTP 302 means that you are redirected to some other URL. You can do a redirect intentionally if you use a RedirectView for example, or accidentally if you forget to write slash at the end of the request URL and you have APPEND_SLASH enabled (in that case, you get HTTP 301 instead of 302).
您最终需要一个斜线:
url(r'^(?P<userName>[0-9a-zA-Z-]+)/task/$', ...
这篇关于AssertionError:302!= 200的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!