iis配置django3.0 报错 argument of type 'WindowsPath' is not iterable

2020-12-01 16:40:06 浏览数 (1)

上篇文章升级了django版本为3.0今天部署到iis时报错:

代码语言:javascript复制
Error occurred:

Traceback (most recent call last):
  File "E:Eventwfastcgi.py", line 854, in main
    result.close()
  File "D:pythonlibsite-packagesdjangohttpresponse.py", line 252, in close
    signals.request_finished.send(sender=self._handler_class)
  File "D:pythonlibsite-packagesdjangodispatchdispatcher.py", line 175, in send
    for receiver in self._live_receivers(sender)
  File "D:pythonlibsite-packagesdjangodispatchdispatcher.py", line 175, in <listcomp>
    for receiver in self._live_receivers(sender)
  File "D:pythonlibsite-packagesdjangodb__init__.py", line 57, in close_old_connections
    conn.close_if_unusable_or_obsolete()
  File "D:pythonlibsite-packagesdjangodbbackendsbasebase.py", line 514, in close_if_unusable_or_obsolete
    self.close()
  File "D:pythonlibsite-packagesdjangodbbackendssqlite3base.py", line 248, in close
    if not self.is_in_memory_db():
  File "D:pythonlibsite-packagesdjangodbbackendssqlite3base.py", line 367, in is_in_memory_db
    return self.creation.is_in_memory_db(self.settings_dict['NAME'])
  File "D:pythonlibsite-packagesdjangodbbackendssqlite3creation.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


StdOut: 

StdErr:

再次刷新报错:

代码语言:javascript复制
Error occurred:

Traceback (most recent call last):
  File "E:Eventwfastcgi.py", line 847, in main
    result = handler(record.params, response.start)
  File "D:pythonlibsite-packagesdjangocorehandlerswsgi.py", line 139, in __call__
    signals.request_started.send(sender=self.__class__, environ=environ)
  File "D:pythonlibsite-packagesdjangodispatchdispatcher.py", line 175, in send
    for receiver in self._live_receivers(sender)
  File "D:pythonlibsite-packagesdjangodispatchdispatcher.py", line 175, in <listcomp>
    for receiver in self._live_receivers(sender)
  File "D:pythonlibsite-packagesdjangodb__init__.py", line 57, in close_old_connections
    conn.close_if_unusable_or_obsolete()
  File "D:pythonlibsite-packagesdjangodbbackendsbasebase.py", line 514, in close_if_unusable_or_obsolete
    self.close()
  File "D:pythonlibsite-packagesdjangodbbackendssqlite3base.py", line 248, in close
    if not self.is_in_memory_db():
  File "D:pythonlibsite-packagesdjangodbbackendssqlite3base.py", line 367, in is_in_memory_db
    return self.creation.is_in_memory_db(self.settings_dict['NAME'])
  File "D:pythonlibsite-packagesdjangodbbackendssqlite3creation.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


StdOut: 

StdErr:

折腾了一天没有解决:开始以为是iis问题,但是看到代码已经是网页报错了,而且好像是数据库问题,关键是数据库还是原来的数据库,都是一样的代码,就是部署到iis不能使用。后来参考了https://blog.csdn.net/qq_45652065/article/details/109704758的文章将settings里的

代码语言:javascript复制
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}

改为:

代码语言:javascript复制
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': str(os.path.join(BASE_DIR, "db.sqlite3")),
    }
}

解决问题,回头看django 2.2版本的settings中确实也是这么写的,不明白为什么到3.0更改并且不能正常运行

记录一下。帮助爬坑

0 人点赞