How to set up a Django project under windows? - django

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.).

Related

Django app conflicts with an existing Python module

I have a function that generates a bash script file '.sh' to create a django project and a few apps.
This is the bash file I generate:
#! /bin/bash
cd projectx
source projectxenv/Scripts/activate
python manage.py startapp app1
python manage.py startapp app2
deactivate
When I execute the bash I generated, it gives me the following errors:
django.core.management.base.CommandError: 'app1' conflicts with the name of an existing Python module and cannot be used as an app name. Please try another name.
django.core.management.base.CommandError: 'app2' conflicts with the name of an existing Python module and cannot be used as an app name. Please try another name.
I don't think app1 and app2 are existing modules, and also, I tried running these commands manually and they work, but when I try ./bash.sh, it doesn't work.

Error while running the django server in eclipse

Type 'manage.py help <subcommand>' for help on a specific subcommand.
Available subcommands:
[django]
check
compilemessages
createcachetable
dbshell
diffsettings
dumpdata
flush
inspectdb
loaddata
makemessages
makemigrations
migrate
runserver
sendtestemail
shell
showmigrations
sqlflush
sqlmigrate
sqlsequencereset
squashmigrations
startapp
startproject
test
testserver
Note that only Django core commands are listed as settings are not properly configured (error: The SECRET_KEY setting must not be empty.).
You need to include the “runserver” flag in what ever setting determines to run manage.py to actually start the server.
E.g
python manage.py runserver
Or to run on a specific port.
python manage.py runserver 1234

django-admin.py startproject can't create project on Windows.

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.

django-admin.py startproject mysite command not working

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.

When should you use django-admin.py versus manage.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.