Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

Django: 'python manage.py runserver' returns 'TypeError: object of type 'WindowsPath' has no len()'

I have created a new django proejct and the only modification I have made is to the settings, changing the database from sqlite to postgres:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': BASE_DIR / 'yachtdrop',
        'USER': 'postgres',
        'PASSWORD': 'passsword',
        'HOST': '127.0.0.1',
        'PORT': '5432',
    }
}

I am using pipenv to manage my virtual environment, my pipfile is as follows:

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
django = "*"
requests = "*"
flask = "*"
psycopg2-binary = "*"

[dev-packages]

[requires]
python_version = "3.9"

When I write the command 'python manage.py runserver', the system returns 'TypeError: object of type 'WindowsPath' has no len()' and I don't understand why this is happening. I am running this on Windows. I have recently reset my Windows system and have a fresh installation of python, pipenv and postgres.

It would be great if anyone could help me out here. Thanks!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Django creates the db.sqllite3 file in the base directory by default but with other databases no need to use 'BASE_DIR' constant in the name. It will goto the host and look for the db file name you have given.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'yachtdrop',
        'USER': 'postgres',
        'PASSWORD': 'passsword',
        'HOST': '127.0.0.1',
        'PORT': '5432',
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...