简体   繁体   中英

Django-admin startproject mysite

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.

Did you add C:\Python27\Scripts to path?

Did you activate virtual-env?

and it should be django-admin.py startproject mysite with.py and should be run in command line.

Thats all I think can help. Good luck: :)

you have opened python terminal just by typing python so i am assuming Python34.exe is already available in your environment path variables.

Now Also you have imported django successfully that means your source directory is also included in env variables.

Now you need to remember that you can not create a project from inside of python shell. So do a gracefull exit by typing exit() and then type django-admin startproject mysite

Let me know if it works...

I had the same problems while trying to start a project. All I did was to open the command prompt as I am using windows and typed:

django-admin.py startproject mysite

I did this without typing python or whatsoever.. Once you have installed python and django properly, this should work.

on windows cmd provide path to django-admin.py

exmaple: c:\Django-2.2.6\django\bin\django-admin.py startproject myproject

this should work...

django-admin.py startproject mysite

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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