简体   繁体   English

突然无法识别 Django-admin.py

[英]Django-admin.py not being recognized suddenly

I tried starting a new Django project yesterday but when I did "django-admin.py startproject projectname" I got an error stating: "django-admin.py is not recognized as an internal or external command."我昨天尝试启动一个新的 Django 项目,但是当我执行“django-admin.py startproject projectname”时,我收到一条错误消息:“django-admin.py 未被识别为内部或外部命令。” The strange thing is, when I first installed Django, I made a few projects and everything worked fine.奇怪的是,当我第一次安装 Django 时,我做了几个项目,一切正常。 But now after going back a few months later it has suddenly stopped working.但是现在几个月后回去后它突然停止工作了。

I've tried looking around for an answer and all I could find is that this typically has to do with the system path settings, however, I know that I have the proper paths set up so I don't understand what's happening.我试过四处寻找答案,我能找到的只是这通常与系统路径设置有关,但是,我知道我设置了正确的路径,所以我不明白发生了什么。 Does anybody have any idea what's going on?有人知道发生了什么吗?

First check the django was installed properly.首先检查django是否安装正确。

import django

EDIT 1编辑 1

If you got exception, try to uninstall and install django.如果出现异常,请尝试卸载并安装 django。

i recommend to do this by pip:我建议通过 pip 执行此操作:

$> easy_install pip


$> pip uninstall django
$> pip install django

Then check the file C:\\Python26\\Scripts\\django-admin.py exists.然后检查文件C:\\Python26\\Scripts\\django-admin.py存在。 you may replace c:\\python26 by your local python installation path.您可以将c:\\python26替换为您本地的 python 安装路径。 if you not found the file, so uninstall and install django, see EDIT 1 above.如果找不到该文件,请卸载并安装 django,请参阅上面的编辑 1

then add C:\\Python26 and C:\\Python26\\Scripts to your path.然后将C:\\Python26C:\\Python26\\Scripts到您的路径中。 see here这里

From python documents :来自python 文档

to the current setting for the PATH environment variable, which you will find in the properties window of “My Computer” under the “Advanced” tab. PATH 环境变量的当前设置,您可以在“我的电脑”的“高级”选项卡下的属性窗口中找到该设置。 Note that if you have sufficient privilege you might get a choice of installing the settings either for the Current User or for System.请注意,如果您有足够的权限,您可以选择为当前用户或系统安装设置。 The latter is preferred if you want everybody to be able to run Python on the machine.如果您希望每个人都能够在机器上运行 Python,则首选后者。

i am totally new to coding, so pardon my amateur answers.我对编码完全陌生,所以请原谅我的业余答案。

I had similar problem - i realized that while my Django was installed on C Drive, my files were saved on D drive and i was trying to run django-admin from D drive in the command prompt which was giving the above error.我遇到了类似的问题 - 我意识到当我的 Django 安装在 C 驱动器上时,我的文件保存在 D 驱动器上,我试图在命令提示符下从 D 驱动器运行 django-admin,这给出了上述错误。 what worked for me was the following对我有用的是以下内容

  1. Located the Django-admin.exe and django-admin.py file which was in below path C:\\Users[Username]\\AppData\\Local\\Programs\\Python\\Python38-32\\Scripts>找到位于以下路径 C:\\Users[Username]\\AppData\\Local\\Programs\\Python\\Python38-32\\Scripts> 中的 Django-admin.exe 和 django-admin.py 文件

  2. copied both these files into the D drive folder where i was trying to create new projects将这两个文件复制到我试图创建新项目的 D 驱动器文件夹中

  3. then on the terminal command prompt (which was set to D Drive projects) ran django-admin startproject [filename] and it created a new file [filename]in that folder and this error was resolved然后在终端命令提示符(设置为 D Drive 项目)上运行 django-admin startproject [filename] 并在该文件夹中创建了一个新文件 [filename],此错误已解决

您可以尝试使用以下代码

py -m django startproject add_your_project_name_here

As per this link you may try,根据此链接,您可以尝试,

python -m django <command> [options] . python -m django <command> [options] .

Where python is the version of the python you are using.其中 python 是您使用的 python 版本。

Usage python -m django startproject <projectname> .用法python -m django startproject <projectname>

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

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