简体   繁体   English

django-admin.py startproject 不工作

[英]django-admin.py startproject is not working

after installing django I tried django-admin.py startproject mysite and that worked, then I got a simple site working and I wanted to start on something real, so I tried django-admin.py startproject newsite and nothing happened.安装 django 后,我尝试了django-admin.py startproject mysite并且成功了,然后我得到了一个简单的站点,我想开始一些真实的事情,所以我尝试了django-admin.py startproject newsite并且什么也没发生。 Whenever I try the command nothing happens now.. any idea what is wrong?每当我尝试命令时,现在什么都没有发生……知道出了什么问题吗?

For anyone stumbling across this now, this problem is a result of Windows not obeying the #!C:\\Path\\To\\Virtualenv\\Scripts\\Python.exe hashbang at the top of django-admin.py, and therefore running it with the wrong python.exe (evidently a virtualenv bug).对于现在遇到这个问题的任何人来说,这个问题是由于 Windows 不遵守 django-admin.py 顶部的 #!C:\\Path\\To\\Virtualenv\\Scripts\\Python.exe hashbang,因此使用错误的python.exe(显然是virtualenv 错误)。

However, with virtualenv active, you can use the following command, which will result in the correct python being used, and everything being ok:但是,当 virtualenv 处于活动状态时,您可以使用以下命令,这将导致使用正确的 python,并且一切正常:

python C:\Path\To\Virtualenv\Scripts\django-admin.py startproject <project_name>

If you are running Windows for a quick fix you can create a batch file with the following values:如果您正在运行 Windows 以进行快速修复,您可以创建一个具有以下值的批处理文件:

@echo off
@echo "Enter Proyect name"
set /p proj_name=
set building="Building django project %proj_name%"
@echo %building%
python c:/Python27/Scripts/django-admin.py startproject %proj_name%
pause

I named the file "django.bat" and to use it you can just simply add a copy in the directory you want to start the project, execute the file and it will ask you for a project name, provide one and then Voila!!我将文件命名为“django.bat”,要使用它,您只需在要启动项目的目录中添加一个副本,执行该文件,它会询问您一个项目名称,然后提供一个,然后瞧!

Hope this helps.希望这会有所帮助。

Do you have a DJANGO_SETTINGS_MODULE environment variable set (presumably from the mysite project)?你有DJANGO_SETTINGS_MODULE环境变量集(大概来自mysite项目)吗? If so, django thinks you're working on the old project and doesn't give you the startproject option.如果是这样,django 会认为您正在处理旧项目,并且不会为您提供startproject选项。 Try unsetting the environment variable and trying again.尝试取消设置环境变量并重试。

对我来说,没有.py扩展名,因为我的窗口中有.exe同名:

C:\Python27\Scripts\django-admin startproject HelloWorld

If everything is installed properly, when you open the command prompt, navigate to the desktop folder with如果一切都安装正确,当你打开命令提示符时,导航到桌面文件夹

cd C:\Users\YOURNAME\Desktop

then type然后输入

django-admin startproject YOURPROJECTNAME

The project should appear on your desktop.该项目应该出现在您的桌​​面上。

If you didn't navigate to your desktop folder and run the command there, your project could be placed in the windows\\system32 folder on the C drive.如果您没有导航到您的桌面文件夹并在那里运行命令,您的项目可能被放置在 C 驱动器上的windows\\system32文件夹中。

Try this instead!试试这个吧! It also works inside virtualenv它也适用于virtualenv

python "C:\Python27\Scripts\django-admin.py" startproject test2

继续到 c:/python**/Scripts/ 你必须在那里找到django-admin.py使用绝对路径解决你的问题。

Try for this commond:尝试这个共同点:

django-admin startproject mysite

instead of django-admin.py startproject mysite.而不是 django-admin.py startproject mysite。

Try this solution:试试这个解决方案:

1) Select a .py file and right click and select Open with... 1)选择一个.py文件并右键单击并选择Open with...
2) Here select Python Launcher for Windows 2)这里选择Python Launcher for Windows

This solution is provided for Windows OS此解决方案是为 Windows 操作系统提供的

I'm on a Mac and had a similar problem after installing with pip3.我在 Mac 上使用 pip3 安装后遇到了类似的问题。 I reinstalled and it corrected the error.我重新安装并纠正了错误。 You can try going to the #django irc channel at irc.freenodes您可以尝试转到 irc.freenodes 上的 #django irc 频道

Try out this way.试试这个方法。

1> Look where your python is installed if cannot find it in C:/ Python(). 1> 如果在 C:/Python() 中找不到,请查看 Python 的安装位置。

$ python
Python 2.6.6 (r266:84297, Aug 24 2010, 18:13:38) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.executable
'c:\\Python26\\python.exe'
>>> sys.exec_prefix
'c:\\Python26'
>>>
>>> print '\n'.join(sys.path)

c:\Python26\lib\site-packages\setuptools-0.6c11-py2.6.egg
c:\Python26\lib\site-packages\nose-1.0.0-py2.6.egg
C:\Windows\system32\python26.zip
c:\Python26\DLLs
c:\Python26\lib
c:\Python26\lib\plat-win
c:\Python26\lib\lib-tk
c:\Python26
c:\Python26\lib\site-packages
c:\Python26\lib\site-packages\win32
c:\Python26\lib\site-packages\win32\lib
c:\Python26\lib\site-packages\Pythonwin
c:\Python26\lib\site-packages\wx-2.8-msw-unicode

2> After that move into Scripts folder. 2> 之后进入 Scripts 文件夹。 There you may find django-admin.py.在那里你可以找到 django-admin.py。 Now copy full path of that file.现在复制该文件的完整路径。

3>Now run this command 3>现在运行这个命令

python path of the file startproject name of Project项目的startproject文件python路径

eg.例如。 python C:\\Users\\UserName\\AppData\\Local\\Programs\\Python\\Python35-32\\Scripts\\django-admin.py startproject mysite python C:\\Users\\UserName\\AppData\\Local\\Programs\\Python\\Python35-32\\Scripts\\django-admin.py startproject mysite

hope this will work.希望这会奏效。

after years I have to answer this question because the answer is changed for WINDOWS now多年后我必须回答这个问题,因为现在WINDOWS的答案已更改

python C:\Path\To\Virtualenv\Scripts\django-admin.exe startproject <project_name>

you can use .exe for windows in Scripts folder您可以在 Scripts 文件夹中为 windows 使用 .exe

Even I faced the same problem.甚至我也面临同样的问题。 I even tried adding the directory to Environmental variables but it was not working, so I had to use python -m django for it, but it didn't satisfy me, so I did a tricky thing.我什至尝试将目录添加到环境变量但它不起作用,所以我不得不使用python -m django ,但它并没有让我满意,所以我做了一件棘手的事情。

Instead of adding the directory to Environmental variables, I copied the installed package and pasted it to the first directory ( default directory ) in environmental variable and it started working.我没有将目录添加到环境变量中,而是复制了已安装的包并将其粘贴到环境变量中的第一个目录(默认目录)中,然后它就开始工作了。

I have a easy solution for this.我有一个简单的解决方案。 normally download the django-admin file from the web the add it to the python\\script folder then add the C:\\python\\script to the environment variable then try the command ie django-admin startproject通常从网络下载 django-admin 文件,将其添加到 python\\script 文件夹,然后将C:\\python\\script到环境变量中,然后尝试命令 ie django-admin startproject

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

相关问题 django-admin.py startproject 库存。 不管用? - django-admin.py startproject Inventory . is not working? django-admin.py startproject mysite 不工作 - django-admin.py startproject mysite isn't working django-admin.py startproject mysite 在 Windows 7 上运行不正常 - django-admin.py startproject mysite not working well on windows 7 django-admin.py startproject mysite无法正常工作python 2.7 - django-admin.py startproject mysite not working python 2.7 如何将“ python…PATH…django-admin.py startproject myprojname”减少为“ django-admin.py startproject myprojname”? - How to reduce “python …PATH…django-admin.py startproject myprojname” to “django-admin.py startproject myprojname”? 如果已经有django项目,如何使用startproject(django-admin.py)? - How to use startproject (django-admin.py) if there is already a django project? django命令“ django-admin.py startproject mysite” - django command “django-admin.py startproject mysite” “ django-admin.py startproject Concept”在virtualenv中不起作用 - “django-admin.py startproject Concept” doesn't work in virtualenv django-admin.py startproject返回无法导入设置&#39;settings&#39; - django-admin.py startproject returns Could not import settings 'settings' django-admin.py startproject mysite不起作用 - Doesn't work django-admin.py startproject mysite
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM