Django-admin startproject mysite [英] Django-admin startproject mysite
问题描述
我是Python和Django的新手.我正在使用Python 3.4.2和Django 1.8我只停留在第一盘中:
C:\ Users \ admin> python在Win32上使用Python 3.4.3(v3.4.3:9b73f1c3e601,2015年2月24日,22:43:06)tel)输入帮助",版权",信用"或许可证"以获取更多信息>>>进口django>>>打印(django.get_version())1.8.3>>>django-admin startproject mysite文件< stdin>",第1行django-admin startproject mysite^ SyntaxError:语法无效
有人可以帮我吗?
您无法运行以下命令:
django-admin startproject mysite
在Python解释器中.
它应该在命令行上运行.我对Windows没有太多经验,但是它也应该与Linux Shell一样工作.
因此,请在命令行上运行以上命令.
我想对此主题做进一步的解释,因为似乎Python语法的一些基础知识在这里并不清楚.
在Windows,MacOS X,GNU/Linux,BSD或任何启动了Python shell或解释器的系统中启动 python
时.您可以在此处运行命令并立即获得输出.
运行以上命令会产生SyntaxError.是什么导致此错误?您已经将 django
导入为模块.在第一部分( django-admin
)中,您将从 django
的值中提取未定义或导入的 admin
的值.是导入的模块,而不是变量. django-admin
用于解释器的数学运算,可以对数字(整数,浮点数)执行.在此之后放置 startproject
是为了Python解释器调用另一个变量(与 mysite
相同).因为假设的计算在 django-admin
之后添加另一个变量而导致SyntaxError.
如果您尝试例如以下表达式,也会发生这种情况:
>>>5-3 2
在解释器中使用 django-admin.py startproject mysite
不会有太大变化.现在,它将查找尚未创建的对象 admin
的属性 py
.
在另一面,如果您运行命令:
django-admin.py startproject mysite
在命令行上,文件 django-admin.py
被执行并解析命令行参数 startproject
和 mysite
.>
也就是说,在Python解释器或命令行中运行命令本质上是不同的.
回答您应该只使用命令而不解释其含义的答案将忽略错误消息,并且并不是真的很有用.
我希望这有助于更好地理解您遇到的问题.
I'm new to Python and Django. I'm using Python 3.4.2 and Django 1.8 I'm stuck in the first set only:
C:\Users\admin>python
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) tel)] on win32
Type "help", "copyright", "credits" or "license" for more
>>> import django
>>> print (django.get_version())
1.8.3
>>> django-admin startproject mysite
File "<stdin>", line 1
django-admin startproject mysite
^ SyntaxError: invalid syntax
Can someone help me with this?
You can't run the following command:
django-admin startproject mysite
within the Python interpreter.
It should be run on the command line. I don't have a lot of experience with Windows, but it should also work like with the Linux shell.
So run the above on the command line.
EDIT:
I would like to give some further explanation on this topic because it seems that some basics of Python syntax aren't really clear here.
When you start python
either in Windows, MacOS X, GNU/Linux, BSD or whatever the Python shell or interpreter is started.
You can run your commands there and get an immediate output.
Running the above command produces SyntaxError. What causes this error? You already imported django
as a module. In the first part (django-admin
) you are extracting the value of admin
which is not defined or imported anywhere from the value of django
which is an imported module and not a variable. django-admin
is for the interpreter a mathematical operation that can be performed on numbers (integers, floats). Putting startproject
after that is for the Python interpreter calling another variable (same for mysite
). Because the hypothetical calculation ends after django-admin
adding another variable after that causes a SyntaxError.
This would also happen if you would try for example the following expression:
>>> 5 - 3 2
Using django-admin.py startproject mysite
in the interpreter doesn't change much. It now looks for an attribute py
of the object admin
that hasn't been created.
On the other side if you run the command:
django-admin.py startproject mysite
on the command line, the file django-admin.py
gets executed and parses the command line arguments startproject
and mysite
.
That said, running the command in the Python interpreter or on the command line are essentialy different things.
The answers saying you should just use the command, without explaining the meaning, are ignoring the error message and aren't really very useful.
I hope this helps for better comprehension of the problems you ran into.
这篇关于Django-admin startproject mysite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!