[Django]-Getting error add() got an unexpected keyword argument 'id' in django

3👍

You are passing parameter in URL but not receiving it in in view function. You should define add function like this

def add(request, id=None):
    pass
    # rest of code

1👍

If you have a method, eg:

@app.route('/transcript/<int:id>', methods=['GET', 'POST'])
def transcript(employeeId):
  if x == 'NoneType': 
        employee = Employee()        
    else:
        employee = Employee(employeeId)

The argument doesn’t match the route, eg employeeId doesn’t equal <int:id>, so we change the argument to id

@app.route('/transcript/<int:id>', methods=['GET', 'POST'])
def transcript(id):
  if x == 'NoneType': 
        employee = Employee()        
    else:
        employee = Employee(employeeId)

Strangely we still get the same error. The trick is that you may not have changed all old occurrences of the old employeeId argument:

@app.route('/transcript/<int:id>', methods=['GET', 'POST'])
def transcript(id):
  if x == 'NoneType': 
        employee = Employee()        
    else:
        employee = Employee(id)

Leave a comment