英文:
Django - How do I solve the problem of adding members?
问题
我正在使用 django-groups-manager。
有一个成员部分。我在录制时遇到错误。我可能漏掉了什么或犯了错误。可能出现在哪里?
> 在 /accounts/register/ 上的 TypeError
>
> Member() 收到了一个意外的关键字参数 'name'
views.py
from groups_manager.models import Group, GroupType, Member
def register_view(request):
form = RegisterForm(request.POST or None)
if form.is_valid():
user = form.save()
new_group_name = form.cleaned_data['new_group_name']
new_group, created = Group.objects.update_or_create(name=new_group_name)
user.groups.add(AGroup.objects.get(name=new_group_name))
member = form.cleaned_data['member']
member = Member.objects.create(name=member)
user.save()
password = form.cleaned_data.get('password1')
new_user = authenticate(username=user.username, password=password)
login(request, new_user)
return redirect('home')
return render(request, 'accounts/form.html', {'form': form, 'title': 'Üye Ol'})
有问题的这一行:
member = Member.objects.create(name=member)
英文:
I'm using django-groups-manager.
There is a member section. I get an error while recording. I'm missing or making mistakes. Where could it be?
> TypeError at /accounts/register/
>
> Member() got an unexpected keyword argument 'name'
views.py
from groups_manager.models import Group, GroupType, Member
def register_view(request):
form = RegisterForm(request.POST or None)
if form.is_valid():
user = form.save()
new_group_name = form.cleaned_data['new_group_name']
new_group, created = Group.objects.update_or_create(name=new_group_name)
user.groups.add(AGroup.objects.get(name=new_group_name))
member = form.cleaned_data['member']
member = Member.objects.create(name=member)
user.save()
password = form.cleaned_data.get('password1')
new_user = authenticate(username=user.username, password=password)
login(request, new_user)
return redirect('home')
return render(request, 'accounts/form.html', {'form': form, 'title': 'Üye Ol'})
This line problematic:
member = Member.objects.create(name=member)
答案1
得分: 2
使用 first_name
,Member 模型中没有 name
参数。
member = Member.objects.create(first_name=member)
英文:
Use first_name
, there is no name
parameter in Member model
member = Member.objects.create(first_name = member)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论