我在引导卡中有6个目标,然后一个提交一个用户的表单可以选择任意数量的目标,因此我将模型编写为包含数据的目标模型,并在html页面goal.html中获取了该数据并且它工作正常,但是选择了一张卡即选定的守门员应作为我表单中隐藏输入的值,我应该如何实现呢?
class goals(models.Model): id=models.IntegerField(primary_key=True) goal = models.CharField(max_length=50,default='0000000') class users(models.Model): email=models.CharField(max_length=50,default='0000000') password=models.CharField(max_length=50,default='0000000') room = models.ForeignKey(rooms,on_delete=models.CASCADE) goal = models.ManyToManyField(goals)
我的表单模板
{% csrf_token %} username Email Password
在views.py
def user_register(request): if request.method == 'POST': username=request.POST["username"] email = request.POST['email'] password = request.POST['password'] room = request.POST["room"] goal = request.POST["goal"] user = users(password=password,email=email) user.room = rooms.objects.get(pk=room) user.goal = goals.objects.get(pk=goal) user.save() return render(request,'home.html')
错误是