在 django 项目中出现 typeError 错误 [英] Getting a typeError error in django project

查看:43
本文介绍了在 django 项目中出现 typeError 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的新项目创建了一个虚拟环境,安装了 django 并启动了新项目.但是,每当我使用 manage.py 运行一行代码时,我都会收到这个长错误.

I created a virtual environment for my new project, installed django and started the new project. However, whenever i run a line of code with manage.py i get this long error.

PS D:My stuffWebsite developmentIsow websiteisow> python manage.py makemigrations
No changes detected
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:Users
ahmaAppDataLocalProgramsPythonPython37libsite-packagesdjangocoremanagement\__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "C:Users
ahmaAppDataLocalProgramsPythonPython37libsite-packagesdjangocoremanagement\__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:Users
ahmaAppDataLocalProgramsPythonPython37libsite-packagesdjangocoremanagementase.py", line 336, in run_from_argv
    connections.close_all()
  File "C:Users
ahmaAppDataLocalProgramsPythonPython37libsite-packagesdjangodbutils.py", line 224, in close_all
    connection.close()
  File "C:Users
ahmaAppDataLocalProgramsPythonPython37libsite-packagesdjangodbackendssqlite3ase.py", line 248, in close
    if not self.is_in_memory_db():
  File "C:Users
ahmaAppDataLocalProgramsPythonPython37libsite-packagesdjangodbackendssqlite3ase.py", line 367, in is_in_memory_db
    return self.creation.is_in_memory_db(self.settings_dict['NAME'])
  File "C:Users
ahmaAppDataLocalProgramsPythonPython37libsite-packagesdjangodbackendssqlite3creation.py", line 12, in is_in_memory_db
    return database_name == ':memory:' or 'mode=memory' in database_name
TypeError: argument of type 'WindowsPath' is not iterable

数据库入口:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}

推荐答案

似乎 NAME 正在被转换为 pathlib.Path (WindowsPath) 对象而不是字符串,然后不能以与 os.path 需要字符串(不是 100% 确定,因为没有深入调查)

It does seem NAME is being converted to pathlib.Path (WindowsPath) object instead of string which then cannot be used in Django in same way as os.path expects strings (Not 100% sure as did not investigate in depth)

所以在字符串中转换是合适的

So casting in string would be appropriate

'NAME': str(os.path.join(BASE_DIR, "db.sqlite3"))

这篇关于在 django 项目中出现 typeError 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆