5👍
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.
- Custom field's to_python not working? – Django
- How can i access the model instance used by a form from a template?
- Django limit_choices_to on user group
- Place to set SQLite PRAGMA option in Django project
- Does django staticfiles skip the middleware?
2👍
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:
settings.BASE_DIR.parent
- Avoid recursive save() when using celery to update Django model fields
- AttributeError: 'property' object has no attribute 'admin_order_field'
Source:stackexchange.com