【发布时间】:2023-03-09 23:19:01
【问题描述】:
我有一个显示用户个人资料页面的 DetailView。该配置文件采用作为 URL 一部分的 slug 名称。例如,/profile/john/ 其中john 是用户名,我们在 john 的个人资料中。如图所示:
class ProfileView(DetailView):
model = User
slug_field = 'username'
template_name = 'oauth/profile.html'
context_object_name = 'user_profile'
def post(self, request):
return render(request, self.template_name)
现在,每当我提交表单时,都会收到一条错误消息:TypeError: post() got an unexpected keyword argument 'slug' 知道了这一点,我在 post 方法中添加了一个新参数,即 slug。但是,当我提交表单时,我得到一个空白页面,其中没有关于用户的详细信息。我们被重定向到同一页面,但这次没有关于用户配置文件的值。我做错了什么?
【问题讨论】: