/ account / register /'tuple'对象上的Django TypeError不可调用

时间:2018-08-09 13:41:54

标签: python django python-3.x django-forms django-class-based-views

问题说明

1-在这里,我试图在向导上渲染两个带有其字段的表单。用户字段和配置文件字段(在OneToOne关系上)。 最终的游戏是完成帐户注册时的个人资料和用户数据。 现在我设法实现了视图中代码的类似变体。真正的问题在于下面

2-创建帐户后,图像将不会保存到数据库。请知道我已经做了以下 -在设置和主网站网址中设置媒体根目录选项 -图像还可以从django管理员保存到媒体室,但是我认为功能与我创建的模型特别相关

我的模板相当大,包含了bootstrap元素,因此我不会添加它,但是它设置为呈现两种形式的特定字段

我的观点有误

我的观点

class RegisterView(CreateView):
    model = User, UserProfile
    form_class = RegistrationForm, UserProfileForm

    def post(self, request, *args, **kwargs):
        user_form = RegistrationForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            if 'profile_photo' in request.FILES:
                profile.profile_photo = request.FILES['profile_photo']
                profile.save()
                registered = True
            else:
                print(user_form.errors, profile_form.errors)
        else:
            user_form = RegistrationForm()
            profile_form = UserProfileForm()

        return render(request, 'accounts/registration.html',
                      {'user_form': user_form, 'profile_form': profile_form, 
        'registered': registered})

我的网址

 path('register/', RegisterView.as_view(), name='register'),

TraceBack

  

文件“ C:\ Users \ Rashid   Thompson \ Desktop \ workspace \ python \ django \ sal1 \ venv \ lib \ site-packages \ django \ core \ handlers \ exception.py“   在内部35。response = get_response(request)

     

文件“ C:\ Users \ Rashid   Thompson \ Desktop \ workspace \ python \ django \ sal1 \ venv \ lib \ site-packages \ django \ core \ handlers \ base.py“   在_get_response 128中。response =   self.process_exception_by_middleware(e,request)

     

文件“ C:\ Users \ Rashid   Thompson \ Desktop \ workspace \ python \ django \ sal1 \ venv \ lib \ site-packages \ django \ core \ handlers \ base.py“   在_get_response 126中。response = wrapd_callback(request,   * callback_args,** callback_kwargs)

     

文件“ C:\ Users \ Rashid   Thompson \ Desktop \ workspace \ python \ django \ sal1 \ venv \ lib \ site-packages \ django \ views \ generic \ base.py“   在视图69中。return self.dispatch(request,* args,** kwargs)

     

文件“ C:\ Users \ Rashid   Thompson \ Desktop \ workspace \ python \ django \ sal1 \ venv \ lib \ site-packages \ django \ views \ generic \ base.py“   在分派89中。return handler(request,* args,** kwargs)

     

文件“ C:\ Users \ Rashid   Thompson \ Desktop \ workspace \ python \ django \ sal1 \ venv \ lib \ site-packages \ django \ views \ generic \ edit.py“   在168中。返回super()。get(request,* args,** kwargs)

     

文件“ C:\ Users \ Rashid   Thompson \ Desktop \ workspace \ python \ django \ sal1 \ venv \ lib \ site-packages \ django \ views \ generic \ edit.py“   在get 133中。return self.render_to_response(self.get_context_data())

     

文件“ C:\ Users \ Rashid   Thompson \ Desktop \ workspace \ python \ django \ sal1 \ venv \ lib \ site-packages \ django \ views \ generic \ edit.py“   在get_context_data 66中。kwargs ['form'] = self.get_form()

     

文件“ C:\ Users \ Rashid   Thompson \ Desktop \ workspace \ python \ django \ sal1 \ venv \ lib \ site-packages \ django \ views \ generic \ edit.py“   在get_form 33中。return form_class(** self.get_form_kwargs())

     

异常类型:/ account / register /处的TypeError异常值:   'tuple'对象不可调用

0 个答案:

没有答案