I'm typing django-admin.py startproject project in my vscode terminal on windows, but when I do it just flashes a screen then closes and the project isn't created. It asked me what to open with and I chose python, but the command doesn't do anything. I'm not getting errors either
I was using django-admin.py instead of django-admin, problem is solved
Also you can create django app by typing folliwing command in terminal
python manage.py startapp HelloWorld
Note- It requires already created project.
Related
I tried of creating project in Windows. When I type django-admin.py startproject projectname it takes but it won't created in folder. Everything is installed and previous project also running fine.
instead of django-admin.py startproject projectname, use
django-admin startproject projectname
In windows, open folder where you want to create the project, point to empty space and press Shift and then right mouse click. Choose the option Open Command Window Here. Then in command window, just enter above command.
in windows 10 try running below command for python version 3.6 and higher from windows powershell:
python -m django startproject django_project_1
whenever i give
django-admin.py startproject
i get a notepad of django-admin. So that means i type in my website inside that ?
i have executed the django-admin.py and django-admin.pyc in cmd also. Still it shows. What should I do ?
You have - for some reason - created a virtual environment inside the actual Python source directory on Windows.
There is nothing wrong with this, except you may face issues when you uninstall or upgrade Python.
To fix your immediate problem, you need to follow these steps:
Close all command prompt windows.
Open a new command prompt.
Type the following and hit ENTER which will activate your virtual environment:
C:\Python27\Scripts\pymote_ven\Scripts\activate.bat
Now, type the following to start your project:
python django-admin.py startproject nameofyourproject
You should also read the documentation because you have confused the directories that are involved.
I have installed python 2.7.10 in windows. I installed django in path c:python27/scripts/with a command pip install django and created project with command django-admin startproject mysite from the same path.
Now to run server i cd to path c:python27/scripts/mysite and ran a command manage.py runserver/ manage.py runserver 0.0.0.0:8000 And this has no any effect.
where did i go wrong, and also i couldn't run with python console. and i couldn't redirect to my project from python CMD. all i did is from windows console.
Edit:
Screenshot of execution
First step was to set the environment variable.
windows key + pause or Control Panel\System and Security\System
Advance system settings (this will open system property)
navigate to Advanced tab > Environment variable
Edit path - append ;c:\python27 in variable value field
Restart CMD
then /python manage.py runserver should work
Trying setting up a virtualenv for your project.
This same issue happened to me when trying to launch the test server
python .\manage.py runserver
from PowerShell on Windows 10. According to the Django site, there might be an issue with the type of arguments being passed from PowerShell.
My workaround was to use a virtualenv. Once that was setup with django installed via pip, the runserver command worked.
The best solution is to install Python from Microsoft Store. In this case, you won't have to worry about the Environmental Variables and Path. Windows will detect all that automatically.
Try this fix guys:
1. Right click on the windows icon/start on the bottom left and run Windows Powershell as admin.
2. Than type cd ~/ and later change the path again to the project folder.
3. type python manage.py runserver and press enter.
had the same problem. fixed it by checking python and django version compatibility. If you're still battling with this update one or the other or ensure they're both compatible with each other in the virtual'env' you're setting up.
good luck.
I think you forgot to add python to environment variables. So, During the installation, click the checkbox named "Add Python 3.9 to PATH" to add in environment variables. or you can simply add the path later.
When you open the command prompt on windows, the default directory might be C:\WINDOWS\System32>
Here, you have to change the directory by just adding cd to the default directory. Then copy the directory of where your project is and paste with one space. So it will be:
C:\yourfolder\yourproject>
Next, use the comman which is, python manage.py runserver
That's all 😅
After setting C:\Python in the environment variables, issuing the following command helped:
py manage.py runserver
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 have added C:\Python27\ for python and C:\Python27\Lib\site-packages\django\bin\ for django to the path variable of environment settings.
But whenever I am running the command
django-admin.py startproject myapp
it is simply opening the django-admin.py file in notepad and not creating any custom django directory and file structure.
I am not able to start with my app development. I didn't faced any problem when I work on ubuntu.
try python django-admin.py startproject myapp
also make sure you have properly installed python ... it should auto-associate files ending in .py