简体   繁体   English

Django 1.4 未知命令:'runserver'

[英]Django 1.4 Unknown command: 'runserver'

Something in my python path must have changed because now I cannot run the.我的 python 路径中的某些内容一定发生了变化,因为现在我无法运行。

python app/manage.py runserver

The output I get is我得到的输出是

Unknown command: 'runserver'
Type 'manage.py help' for usage.

I've looked at my environment's PYTHONPATH and PATH variables, but I can't figure out why its not running.我查看了我环境的 PYTHONPATH 和 PATH 变量,但我不知道为什么它没有运行。

I've found the answer to my question.我找到了我的问题的答案。

  • If you've got an error in your settings, manage.py will swallow the exception and report as if the command does not exist.如果您的设置出现错误,manage.py 将吞下异常并报告该命令不存在。
  • This lead me down the path of incorrectly assuming my python path or venv environment was messed up.这导致我错误地假设我的 python 路径或 venv 环境搞砸了。

If you want to diagnose this issue, run...如果要诊断此问题,请运行...

python app/manage.py help

... and it will show the exception. ...它会显示异常。 This, of course, was what was recommended by the django shell after it had told me that the command was not found.当然,这是 django shell 在告诉我找不到命令后推荐的。

This is clearly a bug in Django 1.4.这显然是 Django 1.4 中的一个错误。 It seems to me, an Exception should be reported regardless of what management command you run.在我看来,无论您运行什么管理命令,都应该报告异常。

Looking through the manager.py code and django.core.management I can come up with some suggestions.查看manager.py代码和django.core.management我可以提出一些建议。

First, check if the file <some_path>/django/core/management/commands/runserver.py exists.首先,检查文件<some_path>/django/core/management/commands/runserver.py存在。

Second, run:二、运行:

>>> import sys
>>> sys.path

If the aforementioned <some_path> is not in this list than you must set the PYTHONPATH variable.如果上述<some_path>不在此列表中,则您必须设置PYTHONPATH变量。

Third, (and that's the longest of all shots) if you have changed the DEFAULT_PORT of runserver , try changing it back to 8000 .第三,(这是所有镜头中最长的一次)如果您更改了runserverDEFAULT_PORT ,请尝试将其改回8000

I agreed with OP.我同意 OP。 I met the same problem, and it turned out to be an error in settings.py :我遇到了同样的问题,结果是settings.py的错误:
In settings.py I use os.environ[something] and those environment variables are loaded in apache start script.在 settings.py 中,我使用os.environ[something]并且这些环境变量加载在 apache 启动脚本中。 If I run manage.py from the command line, it doesn't know what is os.environ[something] thus error occurs.如果我从命令行运行manage.py ,它不知道os.environ[something]os.environ[something]因此会发生错误。

So for anyone here searching for solution, suggestion is to check circumstance difference between running django project and pure manage.py, maybe you'll find what's wrong.因此,对于在这里寻找解决方案的任何人,建议是检查运行 django 项目和纯 manage.py 之间的环境差异,也许您会发现问题所在。

I will add my answer to the same problem I had.我会将我的答案添加到我遇到的相同问题中。 This was unrelated from Django version, but in an old instance of my project I was providing my own Django copy and not installing from pip.这与 Django 版本无关,但在我项目的旧实例中,我提供了自己的 Django 副本,而不是从 pip 安装。 Later I decided to use Pip installed Django.后来我决定用Pip安装Django。

When I pulled the changes on the server, my repo's copy of Django files were deleted but not the .pyc files.当我在服务器上拉取更改时,我的 Django 文件的 repo 副本被删除,但 .pyc 文件没有被删除。 manage.py would still import the old .pyc files making the imports break half way and the error was the same "Unknown command: runserver". manage.py仍会导入旧的 .pyc 文件,使导入中途中断并且错误是相同的“未知命令:runserver”。

Naturally, fully deleting the folder with the .pyc files fixed the problem.自然地,完全删除带有 .pyc 文件的文件夹解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM