Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected error: replace() takes 2 positional arguments but 3 were given

In settings.py I have:

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

Then In some view:

from django.http import HttpResponse
from django.conf import settings


def test_view(request):
    return HttpResponse( settings.BASE_DIR.replace("src", "") )

This gives error: replace() takes 2 positional arguments but 3 were given

It confuses me, how that error appears? also if do:

return HttpResponse( settings.BASE_DIR )

this returns full path, something like: /home/full/path/to/project/src

also this works

 return HttpResponse( "/home/full/path/to/project/src".replace("src", "") )

Can you help me and tell what is wrong with this line:

return HttpResponse( settings.BASE_DIR.replace("src", "") )

?

like image 960
Oto Shavadze Avatar asked Dec 06 '22 08:12

Oto Shavadze


1 Answers

Convert it to string:

str(settings.BASE_DIR).replace("src", "")
like image 136
NKSM Avatar answered Dec 10 '22 11:12

NKSM