【问题标题】:Django python manage.py runserver - Unhandled exceptionDjango python manage.py runserver - 未处理的异常
【发布时间】:2016-05-08 15:59:38
【问题描述】:

我想开始学习 Django 框架,但是我已经遇到了一个问题。我已经设置了 Django 和所有东西,但是当我开始运行服务器时,我的问题就开始了。我写完pythonmanage.py runserver:

C:\Users\Programiranje\Desktop\Django\mysite> python manage.py runserver

它会抛出这样的异常:

Performing system checks...

System check identified no issues (0 silenced).

You have unapplied migrations; your app may not work properly until they are applied.  
Run 'python manage.py migrate' to apply them. May 08, 2016 - 17:47:21 Django version 1.9.6, using settings 'mysite.settings'                        
Starting development server at http://127.0.0.1:8000/ 
Quit the server with CTRL-BREAK. 

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x00000000044E3488>
Traceback (most recent call last):   
File "C:\Python34\lib\site-packages\django-1.9.6py3.4.egg\django\utils\autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)   File "C:\Python34\lib\site-packages\django-1.9.6-py3.4.egg\django\core\management\commands\runserver.py", line 137, in  inner_run
    ipv6=self.use_ipv6, threading=threading)   File "C:\Python34\lib\site-packages\django-1.9.6-py3.4.egg\django\core\servers\basehttp.py", line 188, in run
    httpd = httpd_cls(server_address, WSGIRequestHandler, ipv6=ipv6)   File "C:\Python34\lib\site-packages\django-1.9.6-py3.4.egg\django\core\servers\basehttp.py", line 73, in __init__
    super(WSGIServer, self).__init__(*args, **kwargs)   File "C:\Python34\lib\socketserver.py", line 430, in __init__
    self.server_bind()   File "C:\Python34\lib\site-packages\django-1.9.6-py3.4.egg\django\core\servers\basehttp.py", line 77, in server_bind
    super(WSGIServer, self).server_bind()   File "C:\Python34\lib\wsgiref\simple_server.py", line 50, in server_bind
    HTTPServer.server_bind(self)   File "C:\Python34\lib\http\server.py", line 135, in server_bind
    self.server_name = socket.getfqdn(host)   File "C:\Python34\lib\socket.py", line 463, in getfqdn
    hostname, aliases, ipaddrs = gethostbyaddr(name) UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8e in position 0: invalid start byte

非常感谢任何帮助!

【问题讨论】:

  • 您是否尝试过按照错误提示执行的操作? Run 'python manage.py migrate'?
  • 是的,我有。但它仍然没有工作,因为迁移没有连接到底部错误。
  • 你安装的是什么版本的python和django?
  • 我做了一些搜索,他们实际上说问题发生是因为计算机名称包含非 ascii 字符,例如 ru.stackoverflow.com/questions/485310/… %80/485615#485615
  • 谢谢你们 - 重命名我的电脑确实对我有用:D

标签: python django exception


【解决方案1】:

解决方案:确保您的计算机名称来自 ASCII 表中的字符 :)

【讨论】:

    【解决方案2】:

    我有一个类似但不太有用的错误消息:

    System check identified no issues (0 silenced).
    Unhandled exception in thread started by <function wrapper at 0x00000000051F2518>
    

    (提供零回溯)

    这是由于我的一个应用程序迁移文件夹中存在合并迁移,该文件夹引用了不存在的迁移。迁移引用了另一个 VCS 分支的其他迁移,并且是由同事意外提交的,我已将其合并到我的分支中。

    在此处发布作为答案,因为这是有关此主题的最明显问题。

    【讨论】:

      【解决方案3】:

      我遇到了类似的问题,这是因为我使用的是旧版本的 django。 如果您使用的是 mac,请运行以下命令:

      1.删除当前 django 版本并安装最新的稳定版本。

      pip3 install -U django 
      

      2. 应用迁移(如果有)。确保在您的项目目录中运行此命令。

      python3 manage.py migrate
      

      3.在本地端口 8000 上启动服务器。

      python3 manage.py runserver
      

      干杯!!

      【讨论】:

        【解决方案4】:

        正如错误所示,您尚未应用迁移。 只需运行python manage.py migrate。这样就够了。

        【讨论】:

        • 还没有,因为在教程系列中他们说我们稍后会这样做:) 顺便说一句,这意味着什么。?谢谢:)
        • 它实际上为您创建了迁移,即:它获取您的 models.py 代码并将其转换为一些伪 sql,这样当您运行 migrate 命令时,它将为您创建所有这些表.
        • 哦,谢谢 :) 我发现这个 Django 实际上非常有趣 :)
        • 是的,真的很好。玩得开心:)。是的,请先尝试makemigrations 命令。
        猜你喜欢
        • 1970-01-01
        • 2015-07-25
        • 1970-01-01
        • 2020-02-27
        • 1970-01-01
        • 1970-01-01
        • 2015-11-10
        • 1970-01-01
        相关资源
        最近更新 更多