首页 > 解决方案 > 在本地运行服务器时出现 Django 错误 - AttributeError: 'list' object has no attribute 'read'

问题描述

尝试在 Django 的 VS Code 中运行服务器时出现以下错误。命令:python manage.py runserver 错误:

C:\DjangoServerTest\DjangoServerTest>python manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\base.py", line 328, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\commands\runserver.py", line 60, in execute
    super().execute(*args, **options)
  File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\base.py", line 369, in execute
    output = self.handle(*args, **options)
  File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\commands\runserver.py", line 95, in handle
    self.run(**options)
  File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\commands\runserver.py", line 102, in run
    autoreload.run_with_reloader(self.inner_run, **options)
  File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\autoreload.py", line 601, in run_with_reloader
    exit_code = restart_with_reloader()
  File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\autoreload.py", line 230, in restart_with_reloader
    p = subprocess.run(args, env=new_environ, close_fds=False)
  File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\run\__init__.py", line 145, in __new__
    process = cls.create_process(command, stdin, cwd=cwd, env=env, shell=shell)
  File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\run\__init__.py", line 121, in create_process
    shlex.split(command),
  File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\shlex.py", line 305, in split
    return list(lex)
  File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\shlex.py", line 295, in __next__
    token = self.get_token()
  File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\shlex.py", line 105, in get_token
    raw = self.read_token()
  File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\shlex.py", line 136, in read_token
    nextchar = self.instream.read(1)

AttributeError:“列表”对象没有属性“读取”

你能在这里帮忙吗?

标签: pythondjangoserverlocalhost

解决方案


I too had the same issue. What i did is that i went to control panel -> search -> advanced system settings ->environment variables -> Path then cleared all paths Uninstalled python, and deleted all the python related files in the "C:\Users{user_name}\AppData\Local\Programs" directory And then downloaded the latest one and installed again. Then added the scripts folder and the python folder directory into the PATH. Then installed pip and then django. Now its woking perfectly.

In short remove all the versions of python completely and then install it again. Also clear all the unwanted "paths" in the environment variables.....


推荐阅读