预期的str,字节或os.PathLike对象,而不是列表
Traceback (most recent call last):
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\contrib\admin\options.py", line 604, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\contrib\admin\sites.py", line 223, in inner
return view(request, *args, **kwargs)
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\contrib\admin\options.py", line 1636, in add_view
return self.changeform_view(request, None, form_url, extra_context)
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\decorators.py", line 45, in _wrapper
return bound_method(*args, **kwargs)
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\contrib\admin\options.py", line 1525, in changeform_view
return self._changeform_view(request, object_id, form_url, extra_context)
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\contrib\admin\options.py", line 1564, in _changeform_view
self.save_model(request, new_object, form, not add)
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\contrib\admin\options.py", line 1091, in save_model
obj.save()
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\base.py", line 718, in save
force_update=force_update, update_fields=update_fields)
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\base.py", line 748, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\base.py", line 831, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\base.py", line 869, in _do_insert
using=using, raw=raw)
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\query.py", line 1136, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\sql\compiler.py", line 1288, in execute_sql
for sql, params in self.as_sql():
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\sql\compiler.py", line 1241, in as_sql
for obj in self.query.objs
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\sql\compiler.py", line 1241, in <listcomp>
for obj in self.query.objs
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\sql\compiler.py", line 1240, in <listcomp>
[self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields]
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\sql\compiler.py", line 1192, in pre_save_val
return field.pre_save(obj, add=True)
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\fields\files.py", line 288, in pre_save
file.save(file.name, file.file, save=False)
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\fields\files.py", line 87, in save
self.name = self.storage.save(name, content, max_length=self.field.max_length)
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\files\storage.py", line 48, in save
name = self.get_available_name(name, max_length=max_length)
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\files\storage.py", line 72, in get_available_name
while self.exists(name) or (max_length and len(name) > max_length):
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\files\storage.py", line 308, in exists
return os.path.exists(self.path(name))
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\files\storage.py", line 321, in path
return safe_join(self.location, name)
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\files\storage.py", line 201, in location
return os.path.abspath(self.base_location)
File "C:\Users\Kamil\AppData\Local\Programs\Python\Python37\lib\ntpath.py", line 521, in abspath
path = os.fspath(path)
TypeError: expected str, bytes or os.PathLike object, not list
[18/Oct/2018 17:20:38] "POST /en/admin/verification/document/add/ HTTP/1.1" 500 201568
[18/Oct/2018 17:20:40] "GET /en/admin/verification/document/add/ HTTP/1.1" 200 6120
当我尝试在django中使用内置的admin将记录添加到数据库时,出现了这样的错误。无法理解问题所在,请帮助我了解发生了什么。
在models.py中有一个类可以容纳其他应用程序中的用户,其中有两个ImageField()和一个布尔值。
答案 0 :(得分:0)
MEDIA_ROOT = [
os.path.join(BASE_DIR, 'media')
]
settings.py中的一个问题,我想在django 2.1中路径已更改,因此我遵循了过时的教程。
解决方案:默认情况下,删除MEDIA_ROOT属性是一个媒体文件夹。 或设置
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
没有列表