Django:太多值无法解包(预期2)

时间:2020-01-25 01:46:04

标签: django django-queryset

我是Django的新手。

在我的Django view.py中,我具有以下get方法:export class User extends Component { constructor(props){ super(props); this.state = {users:[], addModalShow : false, editModalShow: false} } render(){ const {users, userid, firstname, lastname, useremail, mobilenumber, dateofbirth, lastmodified} = this.state; let addModalClose =() => this.setState({addModalShow:false}); let editModalClose =() => this.setState({editModalShow:false}); return( <div> <ButtonToolbar> <Button variant='outline-dark' style={{margin:"auto"}} onClick={()=> this.setState({addModalShow:true})}> Add User </Button> <AddUserModal show={this.state.addModalShow} onHide={addModalClose} /> </ButtonToolbar> <Table responsive borderless style={{borderRadius:"0.3em"}} striped hover size="sm" variant="dark" className="mt-4"> <thead> <tr> <th>Id</th> <th>First Name</th> <th>Last Name</th> <th>Email</th> <th>Mobile Number</th> <th>Date of Birth</th> <th>Last Modified</th> <th>Edit</th> <th>Delete</th> </tr> </thead> <tbody> {users.map(user=> <tr key = {user.Id}> <td>{user.Id}</td> <td>{user.firstName}</td> <td>{user.lastName}</td> <td>{user.Email}</td> <td>{user.mobileNumber}</td> <td>{moment(new Date(user.dateOfBirth)).format('YYYY-MM-DD')}</td> <td>{user.lastModified}</td> <td> <ButtonToolbar> <Button className="mr-2" variant="outline-light" onClick={()=> { this.setState({ editShowModal: true }); }}> Edit User </Button> <EditUserModal show={this.state.editModalShow} userid={user.Id} firstname={user.firstName} lastname={user.lastName} useremail={user.Email} mobilenumber={user.mobileNumber} dateofbirth={user.dateOfBirth} onHide={editModalClose} /> </ButtonToolbar> </td> <td> <Button variant="outline-danger" onClick={()=> this.deleteUser(user.Id)} >Delete</Button> </td> </tr> )} </tbody> </Table> </div> ) } },它返回结果。

当我用如下字符串替换时:

customer_list = Customer.objects.filter(CustId = '1001')

我收到以下错误:

要解包的值太多(预期为2)

任何帮助都很感激。

2 个答案:

答案 0 :(得分:0)

@Deysgroup,您好,如果您想发送类似的消息,可以使用getQueryString={'CustId': '1001'},然后使用customer_list = Customer.objects.filter(**getQueryString)调用该函数,希望此答案对您有所帮助。

答案 1 :(得分:0)

您尝试过使用字典吗?

看看this question,也许可以帮助您理解问题。

getQueryString = {'CustId': '1001'}
customer_list = Customer.objects.filter(**getQueryString)