在Django测试期间,如何通过客户端将帖子的ID传递给帖子?
def test_sharing_post_through_email(self):
form = {'name': 'Martin', 'email': '[email protected]', 'to': '[email protected]'}
response = self.client.post('/<int:id>/share/', data={'post': self.post, 'form': form})
response.user = self.user
self.assertEqual(response.status_code, 200)
self.assertIsInstance(response.context, dict)
self.assertEqual(response.context['sent'], True)
如何将ID传递给那里的URL?
def test_sharing_post_through_email(self):
form = {'name': 'Martin', 'email': '[email protected]', 'to': '[email protected]'}
response = self.client.post('/<int:id>/share/', data={'post': self.post, 'form': form})
response.user = self.user
self.assertEqual(response.status_code, 200)
self.assertIsInstance(response.context, dict)
self.assertEqual(response.context['sent'], True)
how can I pass the ID to the url there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该从
django.urls
使用反向
。让我们在urls.py
as中定义您的URL,as:您可以以相反的方式传递 id :
您必须在反向调用中使用该应用程序名称。如果您的目标视图在应用程序“主页”中:
You should use
reverse
fromdjango.urls
. Lets supose your url is defined inurls.py
as:You could pass the id with reverse as:
You'll have to use the app name in the reverse calling. If your targeted view is in the app "home":