{"title":"错误调试","version":"4.2","locale":"zh-hans","docname":"faq/troubleshooting","url":"/zh-hans/4.2/faq/troubleshooting/","canonical":"https://djangodocs.dev/zh-hans/4.2/faq/troubleshooting/","summary":"本页包含了开发Django应用过程中一些常见错误和问题的处理建议。 运行 django-admin 时遇到的问题 Link to this heading # command not found: django-admin Link to this heading # 如果你是通过 pip 安装 Django 的，…","html":"<h1>错误调试<a class=\"heading-anchor\" href=\"#troubleshooting\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>本页包含了开发Django应用过程中一些常见错误和问题的处理建议。</p>\n<section id=\"problems-running-django-admin\">\n<span id=\"troubleshooting-django-admin\"></span><h2>运行 <code class=\"docutils literal notranslate\"><span class=\"pre\">django-admin</span></code> 时遇到的问题<a class=\"heading-anchor\" href=\"#problems-running-django-admin\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<section id=\"command-not-found-django-admin\">\n<h3><code class=\"docutils literal notranslate\"><span class=\"pre\">command</span> <span class=\"pre\">not</span> <span class=\"pre\">found:</span> <span class=\"pre\">django-admin</span></code><a class=\"heading-anchor\" href=\"#command-not-found-django-admin\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>如果你是通过 <code class=\"docutils literal notranslate\"><span class=\"pre\">pip</span></code> 安装 Django 的，<a class=\"reference internal\" href=\"/zh-hans/4.2/ref/django-admin/\"><span class=\"doc\">django-admin</span></a> 应该在你的系统路径中。如果它不在你的路径中，请确保你已经激活了你的虚拟环境，你可以尝试运行等效的命令 <code class=\"docutils literal notranslate\"><span class=\"pre\">python</span> <span class=\"pre\">-m</span> <span class=\"pre\">django</span></code>。</p>\n</section>\n<section id=\"macos-permissions\">\n<h3>macOS 的权限问题<a class=\"heading-anchor\" href=\"#macos-permissions\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>如果你正在使用 macOS，你可能看到“permission denied”提示，当你尝试运行``django-admin``的时候。这是因为在像 macOS 这种类Unix系统中，一个文件在它被当作程序执行之前必须被标记为“可执行”。为了解决这个问题，打开终端并且进入 <span class=\"xref std std-doc\">django-admin `的安装目录（使用``cd``命令），然后执行命令``sudo chmod +x django-admin`</span>.</p>\n</section>\n</section>\n<section id=\"miscellaneous\">\n<h2>杂项<a class=\"heading-anchor\" href=\"#miscellaneous\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<section id=\"i-m-getting-a-unicodedecodeerror-what-am-i-doing-wrong\">\n<h3>我遇到了错误信息 <code class=\"docutils literal notranslate\"><span class=\"pre\">UnicodeDecodeError</span></code>。 我哪里做错了？<a class=\"heading-anchor\" href=\"#i-m-getting-a-unicodedecodeerror-what-am-i-doing-wrong\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>当包含非 ASCII 序列的字节字符串转换为 Unicode 字符串并且指定的编码不正确时，会发生此类错误。输出通常如下所示：</p>\n<div class=\"code-block\" data-language=\"pytb\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Pytb</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Pytb code\"><code><span class=\"x\">UnicodeDecodeError: &#39;ascii&#39; codec can&#39;t decode byte 0x?? in position ?:</span>\n<span class=\"x\">ordinal not in range(128)</span>\n</code></pre></div>\n<p>解决方案主要取决于上下文，但是这里有两个常见的陷阱产生这个错误：</p>\n<ul class=\"simple\">\n<li><p>您的系统语言环境可能是默认的ASCII，比如类UNIX系统上的 “C” （可通过命令 <code class=\"docutils literal notranslate\"><span class=\"pre\">locale</span></code> 进行检查）。如果是这种情况，请参考您的系统文档以了解如何将其更改为UTF-8语言环境。</p></li>\n</ul>\n<p>关联资源：</p>\n<ul class=\"simple\">\n<li><p>：文档：Django 中的 Unicode&lt;/ref/unicode&gt;</p></li>\n<li><p><a class=\"reference external\" href=\"https://wiki.python.org/moin/UnicodeDecodeError\">https://wiki.python.org/moin/UnicodeDecodeError</a></p></li>\n</ul>\n</section>\n</section>","rootId":"troubleshooting","toc":[{"title":"运行 django-admin 时遇到的问题","anchor":"problems-running-django-admin","children":[{"title":"command not found: django-admin","anchor":"command-not-found-django-admin","children":[]},{"title":"macOS 的权限问题","anchor":"macos-permissions","children":[]}]},{"title":"杂项","anchor":"miscellaneous","children":[{"title":"我遇到了错误信息 UnicodeDecodeError。 我哪里做错了？","anchor":"i-m-getting-a-unicodedecodeerror-what-am-i-doing-wrong","children":[]}]}],"breadcrumbs":[{"docname":"faq/index","title":"Django FAQ","url":"/zh-hans/4.2/faq/"}],"prev":{"docname":"faq/contributing","title":"FAQ：贡献代码","url":"/zh-hans/4.2/faq/contributing/"},"next":{"docname":"ref/index","title":"API 参考","url":"/zh-hans/4.2/ref/"},"formats":{"html":"/zh-hans/4.2/faq/troubleshooting/","markdown":"/zh-hans/4.2/faq/troubleshooting.md","json":"/zh-hans/4.2/faq/troubleshooting.json"},"source":"https://github.com/django/django/blob/stable/4.2.x/docs/faq/troubleshooting.txt","official":"https://docs.djangoproject.com/zh-hans/4.2/faq/troubleshooting/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0"],"inLocales":["en","zh-hans","fr","ja","id","it","pt-br","ko","es","el","pl"]}