本地变量' post'在分配之前引用

时间:2018-01-17 06:20:16

标签: django django-models django-forms django-views

我试图通过表单将当前登录的用户名分配给现有模型。但在保存表单时遇到问题

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);

1 个答案:

答案 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')

在视图中尝试此操作