[Solved]-Unexpected error: replace() takes 2 positional arguments but 3 were given


Convert it to string:

str(settings.BASE_DIR).replace("src", "")


You’re not calling the replace method of the str stype, but the one of the Path class from pathlib (because BASE_DIR is a Path instance).

It only takes two args (eg. my_path.replace(target)), therefore the exception.

Docs here about what is does (basically renaming a file or directory).

Cast your Path instance to a string.


From Django 3.1 BASE_DIR is by default set to new pathlib module Path object as documented

from source

BASE_DIR = Path(__file__).resolve().parent.parent

Coincidentally Path has also .replace() method but it does not have same use case as string replace

You might want to use instead parent accessor:


Leave a comment