I am trying to create very first project using django but stuck at very first step itself. Whenever I give django-admin.py startproject mysite command not working command, nothing happens and help related information comes up on command prompt. I have set PYTHON_HOME, PATH variables set correctly. I am using python 2.7.
My command prompt looks as follows :
C:\Shekhar\djangoWorld>c:\Python27\Scripts\django-admin.py startproject mysite
Usage: django-admin.py subcommand [options] [args]
Options:
-v VERBOSITY, --verbosity=VERBOSITY
Verbosity level; 0=minimal output, 1=normal output,
2=verbose output, 3=very verbose output
--settings=SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
--pythonpath=PYTHONPATH
A directory to add to the Python path, e.g.
"/home/djangoprojects/myproject".
--traceback Print traceback on exception
--version show program's version number and exit
-h, --help show this help message and exit
Type 'django-admin.py help <subcommand>' for help on a specific subcommand.
Available subcommands:
[django]
cleanup
compilemessages
createcachetable
dbshell
diffsettings
dumpdata
flush
inspectdb
loaddata
makemessages
reset
runfcgi
Why django is not creating project for me?
Please help !!
Add 'python' before django-admin.py (or add full path to python.exe).
C:\Shekhar\djangoWorld>python c:\Python27\Scripts\django-admin.py startproject mysite
Your Django installation is broken. Reinstall.
In my case I'm using Canopy on Windows 8 and the only way it worked for me was putting python command also the full path of django-admin.py like this example "c:> python C:\Users\\AppData\Local\Enthought\Canopy\User\Scripts\django-admin.py startproject ".
I have Canopy installed as well. I copied the django-admin file into the directory where I wanted to install my first project. I opened up the python command prompt and typed in:
python django-admin.py startproject mysite
That did the trick for me. Thanks to those who posted because that got me going down the right path.
Related
When I run the python manage.py startapp "app name" command in my Django project directory nothing happens... Every other manage.py command works without problem.
What could be the problem?
Thanks a lot!!
Andrew
The first line in manage.py breaks the file on windows. The first line should look like this:
#!/usr/bin/env python
Removing it fixes the issue for me. Please try this is really helpful. Thanks
This problem occurs due to Python Path is not set, you can reinstall python and check the box that says "Add to Path 3.9"
Are you running the correct version of Python and correct version of Django?
To check Django:
python manage.py --version
Make sure you are running the right versions, if you are have Python 3 and Python 2 installed you may have multiple versions of Django.
Try to set environment variables on the command line? This path is if you were using vagrant.
PYTHONPATH=/vagrant/www DJANGO_SETTINGS_MODULE=settings django-admin.py startapp
Then try manage.py does it work? Without setting envs on the command line?
Adding a virtual environment is necessary to get the above command working. In the virtual environment you can specifically install Django and it is done so as to ensure that no other package interfers with the Django framework. I was also facing the same issue but after creating a virtual environment, things became super easy!!!
I would recommend using pycharm as creating a virtual environment is just as easy as running a hello world program!!. Also paste the following code at the settings.py script at the end :
ALLOWED_HOSTS=['*']
Also specify the correct directory while running in the terminal. Be sure to check that the code should be written inside the project directory.
Hope that helps :)
I was facing a similar issue and saw this question. Tried the methods mentioned by some of the users but it did not work. Surprisingly the only thing I had to do was remove the word "python" from the command. All I typed in the command line was - manage.py startapp "appname"
I have no idea what difference does it make or how I made it work, but if anyone has a similar problem I hope your issue gets resolved.
I think it maybe because i had previously added the directory I am working in the PATH variable. Not sure. Someone has an opinion on this, do share.
I think i may have found the solution. If you're running on python 3.7 or above, try setting your directory to ~\YourProjectName\YourProjectName with the cd commmand then type py -m django startapp <appName>
The command
$ python-admin startapp main
returns the error " bash: python-admin: command not found".
I was able to resolve using the following command instead
$ py -m django startapp main
if some of you are following old tutorials on django then after you have python version 3.7 or above then the command "python manage.py startapp 'appname'" doesnt works.//well it didn't work for me so insted of that command you can use "py -m django startapp 'appname'"
it worked for me so you can also try that..
the command -> manage.py startapp 'appname'" works for python version upto 3.7 and for 3.7 and above version used command -> "py -m django startapp 'appname'" it works for me...
I am on Windows server, and when I type "django-admin.py startproject", I'm getting the following message. Looks like I'm not using the command properly, but it is correct. My Django version is Django 1.10, and Pythhon 2.7.
c:\test>django-admin.py startproject mysite
Usage: django-admin.py subcommand [options] [args]
Options:
-v VERBOSITY, --verbosity=VERBOSITY
Verbosity level; 0=minimal output, 1=normal output,
2=verbose output, 3=very verbose output
--settings=SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
--pythonpath=PYTHONPATH
A directory to add to the Python path, e.g.
"/home/djangoprojects/myproject".
--traceback Raise on exception
--version show program's version number and exit
-h, --help show this help message and exit
Type 'django-admin.py help <subcommand>' for help on a specific subcommand.
Available subcommands:
[django]
check
cleanup
compilemessages
createcachetable
dbshell
diffsettings
dumpdata
flush
inspectdb
loaddata
makemessages
runfcgi
runserver
shell
sql
sqlall
sqlclear
sqlcustom
sqldropindexes
sqlflush
sqlindexes
sqlinitialdata
sqlsequencereset
startapp
startproject
syncdb
test
testserver
validate
Simply try this :
django-admin startproject projectname
Thanks.
Try with
python djangoadmin.py startproject mysite
or check this answer.
I'm trying to set up a django project but I fail.
First of all I have a Windows 8 machine.
My PATH variable is that:
C:\Python34\;C:\Python34\Scripts;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;-vm
C:\Program Files (x86)\Java\jre7\bin\javaw.exe
When I open PyCharm for example and type import django there comes no error message
Then, in the officialy tutorial "Writing your first Django app" they say I have to create a project with this command django-admin.py startproject mysite
I tried this via command prompt with administrative privileges under Windows from these folders:
C:\Python34\Scripts
&
C:\Python34\Lib\site-packages\django\bin
In both folders I can find a django-admin.py.
There comes no error message, it just rushes through and is not creating any folders. What am I missing here?
The output of the command prompt is this:
C:\Python34\Lib\site-packages\django\bin>django-admin.py startproject myApp
Usage: django-admin.py subcommand [options] [args]
Options:
-v VERBOSITY, --verbosity=VERBOSITY
Verbosity level; 0=minimal output, 1=normal output,
2=verbose output, 3=very verbose output
--settings=SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
--pythonpath=PYTHONPATH
A directory to add to the Python path, e.g.
"/home/djangoprojects/myproject".
--traceback Raise on exception
--no-color Don't colorize the command output.
--version show program's version number and exit
-h, --help show this help message and exit
Type 'django-admin.py help <subcommand>' for help on a specific subcommand.
Available subcommands:
[django]
check
compilemessages
createcachetable
dbshell
diffsettings
dumpdata
flush
inspectdb
loaddata
makemessages
makemigrations
migrate
runfcgi
runserver
shell
sql
sqlall
sqlclear
sqlcustom
sqldropindexes
sqlflush
sqlindexes
sqlinitialdata
sqlmigrate
sqlsequencereset
squashmigrations
startapp
startproject
syncdb
test
testserver
validate
Note that only Django core commands are listed as settings are not properly conf
igured (error: Requested setting INSTALLED_APPS, but settings are not configured
. You must either define the environment variable DJANGO_SETTINGS_MODULE or call
settings.configure() before accessing settings.).
I am trying to install django locally on ubuntu but cannot get it to recognize admin-django.py. I performed the subversion checkout, moved the django directory on to the python path and then created a symlink to django-admin.py. I can import django from within the python interpreter but cannot run
django-admin.py startproject mysite
Any ideas what I could be missing?
You probably need to give the full path to django-admin.py. Giving us the error message would help.
If your symlink is in the current directory (you don't say) then:
./django-admin.py
should work. Otherwise its
/usr/wherever/python/site-packages/something/django/huh/django-admin.py
Make sure that the django-admin.py file is executable:
chmod +x django-admin.py
Background:
When I run the django-admin.py loaddata example.json I get this error. "ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined." I understand the problem. It needs the DJANGO_SETTINGS_MODULE to be able to access the database to do this import. I've had this problem before and I've managed to side step it thus far.
In reading the docs, I discovered that the manage.py is a wrapper for django-admin.py; it puts the project on the sys.path and sets the DJANGO_SETTINGS_MODULE environment. Woot! Whoa! I know how to fix my problem.
Soo...
Why do the Django documentation code examples use django-admin.py instead of manage.py when demonstrating subcommands such as loaddata and dumpdata?
If your DJANGO_SETTINGS_MODULE environment variable is set, you can use django-admin.py from any working directory, whereas you need to be in the project directory to use ./manage.py (or have it in your path).
Use virtualenv, and have DJANGO_SETTINGS_MODULE set by bin/activate, and then you can use django-admin.py.
Why do the Django documentation code examples using django-admin.py instead of manage.py when demonstrating subcommands such as loaddata and dumpdata?
Well, because these scripts are the same in priciple, with the differences, you already mentioned. The Django docs also mention
django-admin.py <subcommand> [options]
manage.py <subcommand> [options]
side by side. Usually you use django-admin.py to start a new project or application and manage.py to do the rest.