still 毕业设计,搭建django来到了最后一步,在terminal下运行python manage.py runserver,但是。。。
无法进入,查看报错,提示是diango的线程出了问题
Exception in thread django-main-thread:
整体报错如下,完全一堆我这个小菜鸡看不懂的东西:
Traceback (most recent call last):
File "F:\Python3.7.7\lib\threading.py", line 926, in _bootstrap_inner
self.run()
File "F:\Python3.7.7\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "F:\Project-Python\learning_log\venv\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "F:\Project-Python\learning_log\venv\lib\site-packages\django\core\management\commands\runserver.py", line 140, in inner_run
ipv6=self.use_ipv6, threading=threading, server_cls=self.server_cls)
File "F:\Project-Python\learning_log\venv\lib\site-packages\django\core\servers\basehttp.py", line 210, in run
httpd = httpd_cls(server_address, WSGIRequestHandler, ipv6=ipv6)
File "F:\Project-Python\learning_log\venv\lib\site-packages\django\core\servers\basehttp.py", line 71, in __init__
super().__init__(*args, **kwargs)
File "F:\Python3.7.7\lib\socketserver.py", line 452, in __init__
self.server_bind()
File "F:\Python3.7.7\lib\wsgiref\simple_server.py", line 50, in server_bind
HTTPServer.server_bind(self)
File "F:\Python3.7.7\lib\http\server.py", line 139, in server_bind
self.server_name = socket.getfqdn(host)
File "F:\Python3.7.7\lib\socket.py", line 676, in getfqdn
hostname, aliases, ipaddrs = gethostbyaddr(name)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe7 in position 0: invalid continuation byte
但是小白还算有点脑子,这句话我还是看懂了的:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe7 in position 0: invalid continuation byte
应该是关于编码的问题,在此基础上我搜遍了全网,终于有了一点线索!
PS:网上大部分原因给出的无法打开的原因都是端口问题或者没有迁移数据库 python manage.py migrate
但是!我这个就有点特殊,原来是我的电脑设备的名称是中文!
仔细看报错的倒数第二行
hostname, aliases, ipaddrs = gethostbyaddr(name)
好,这就去修改电脑名!
修改后,再次运行 python manage.py runserver 就成功啦
无报错
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
March 15, 2022 - 23:05:29
Django version 3.2.12, using settings 'learninglog.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
进入127.0.0.1即可
这次错误给了以后出现编码问题提供了思路,那就是很可能是文件里面或者什么地方出现了中文,然后无法编码的情况,Mark到位。