form._raw_value(fieldname) gone in Django 1.9

2019-04-17 11:27发布

I have code which uses form._raw_value(fieldname).

This is gone in Django 1.9.

Is there a way to access the raw value in 1.9+?

Update

I am only migrating the code to Django 1.9. Up to now I have no deeper understanding of what's going on there in detail.

1条回答
闹够了就滚
2楼-- · 2019-04-17 12:06

Looking at the source code, the _raw_value method is only 3 lines long, so it would be easy to add it as a function to your code.

def _raw_value(form, fieldname):
    field = form.fields[fieldname]
    prefix = form.add_prefix(fieldname)
    return field.widget.value_from_datadict(form.data, form.files, prefix)

Then change your code from form._raw_value(fieldname) to _raw_value(form, fieldname).

查看更多
登录 后发表回答