Reputation: 345
I am following up a django tutorial and I have just installed django using pip install django=2.1
and it was successfully installed then I created a project using django-admin startproject App .
after that I am trying to runserver using python manage.py runserver
and I am getting a TypeError: argument 1 must be str not WindowsPath
.
Performing system checks...
System check identified no issues (0 silenced).
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x02AC2D20>
Traceback (most recent call last):
File "C:\Users\ASUS\PycharmProjects\WebDev\venv\lib\site-packages\django\utils\autoreload.py", line 225, in
wrapper
fn(*args, **kwargs)
File "C:\Users\ASUS\PycharmProjects\WebDev\venv\lib\site-packages\django\core\management\commands\runserver
.py", line 120, in inner_run
self.check_migrations()
File "C:\Users\ASUS\PycharmProjects\WebDev\venv\lib\site-packages\django\core\management\base.py", line 442
, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "C:\Users\ASUS\PycharmProjects\WebDev\venv\lib\site-packages\django\db\migrations\executor.py", line 1
8, in __init__
self.loader = MigrationLoader(self.connection)
File "C:\Users\ASUS\PycharmProjects\WebDev\venv\lib\site-packages\django\db\migrations\loader.py", line 49,
in __init__
self.build_graph()
File "C:\Users\ASUS\PycharmProjects\WebDev\venv\lib\site-packages\django\db\migrations\loader.py", line 209
, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "C:\Users\ASUS\PycharmProjects\WebDev\venv\lib\site-packages\django\db\migrations\recorder.py", line 6
1, in applied_migrations
if self.has_table():
File "C:\Users\ASUS\PycharmProjects\WebDev\venv\lib\site-packages\django\db\migrations\recorder.py", line 4
4, in has_table
return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor(
))
File "C:\Users\ASUS\PycharmProjects\WebDev\venv\lib\site-packages\django\db\backends\base\base.py", line 25
5, in cursor
return self._cursor()
File "C:\Users\ASUS\PycharmProjects\WebDev\venv\lib\site-packages\django\db\backends\base\base.py", line 23
2, in _cursor
self.ensure_connection()
File "C:\Users\ASUS\PycharmProjects\WebDev\venv\lib\site-packages\django\db\backends\base\base.py", line 21
6, in ensure_connection
self.connect()
File "C:\Users\ASUS\PycharmProjects\WebDev\venv\lib\site-packages\django\db\backends\base\base.py", line 19
4, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\ASUS\PycharmProjects\WebDev\venv\lib\site-packages\django\db\backends\sqlite3\base.py", line
159, in get_new_connection
conn = Database.connect(**conn_params)
TypeError: argument 1 must be str, not WindowsPath
here is settings.py:
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent
DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'App.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'App.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
Am i missing something? Please help! Also stackoverflow is not allowing me to add more info because it says my post is mostly code.
Upvotes: 3
Views: 3239
Reputation: 24592
The issue is here
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
^^^^^^^^^^^^^^^^^^^^^^^
}
}
BASE_DIR / 'db.sqlite3'
returns a Pathlib object(WindowsPath
if you are using windows otherwise PosixPath
), where as NAME
actually expect a string. So change from
BASE_DIR / 'db.sqlite3
to
str(BASE_DIR / 'db.sqlite3')
in order to get a string representation of Path
object.
Upvotes: 9