相关疑难解决方法(0)

Django表单预览 - 如何使用'cleaning_data'

感谢Insin回答了与此相关的上一个问题.

他的回答有效并且运作良好,但是,我对'cleaning_data'的提供感到困惑,或者更确切地说,如何使用它?

class RegistrationFormPreview(FormPreview):
    preview_template    = 'workshops/workshop_register_preview.html'
    form_template       = 'workshops/workshop_register_form.html'

    def done(self, request, cleaned_data):
        # Do something with the cleaned_data, then redirect
        # to a "success" page. 

        registration            = Registration(cleaned_data)
        registration.user       = request.user
        registration.save()
        # an attempt to work with cleaned_data throws the error: TypeError 
        # int() argument must be a string or a number, not 'dict'
        # obviously the fk are python objects(?) and not fk_id
        # but how to proceed here in an easy way?



        # …
Run Code Online (Sandbox Code Playgroud)

python django django-models django-forms

3
推荐指数
1
解决办法
7119
查看次数

标签 统计

django ×1

django-forms ×1

django-models ×1

python ×1