[Fixed]-Django KeyError when trying to format foreignkey

1👍

The problem is that your string contains named arguments (e.g. {comp}), but you are using positional arguments when you call format()

You can either remove the names from the braces in your string:

filepath = '{}/utils/locndb/{}.{}'.format(comp, vehdir, filename)

or use keyword arguments when calling format:

filepath = '{comp}/utils/locndb/{vehdir}.{filename}'.format(comp=comp, vehdir=vehdir, filename=filename)

Leave a comment