我试图通过表单将当前登录的用户名分配给现有模型。但在保存表单时遇到问题
class Login extends React.Component {
constructor(props){
super(props)
this.state = {
username : '',
password : ''
}
}
submit = (e) => {
/* console.logging "Some response"*/
console.log(this.props.doLogin(this.state))
}
render(){
return (
<form onSubmit={this.submit}>/* some login element */</form>
)
}
}
export default connect(null, {LoginAction})(Login);
答案 0 :(得分:0)
if request.method == "POST":
form=NotForm(request.POST)
if form.is_valid():
post = form.save(commit=False)
post.user = request.user.get_username()
post.save()
return redirect('base')
在视图中尝试此操作