setting manage.py to executable is not working - django

I'm trying to follow a tutorial on django.
In the directory where manage.py is located I've run the following command in iTerm to set the file to execute: chmod +x manage.py
However when I type in manage.py startapp greetings and hit return, I get the following error:
zsh: command not found: manage.py
But when I run ls -l, it shows what I believe to be the correct permissions:
-rwxr-xr-x
Also, if I enter ./manage.py I get this error:
zsh: permission denied: ./manage.py
What am I doing wrong?

Normally you would use:
python manage.py <cmd>

There is no space between startapp.
Also you need to make manage.py executable to execute it. Do chmod +x manage.py to make it executable. Alternatively you can do python manage.py <cmd> instead.

Make sure that the first line in manage.py is #!/usr/bin/env python so that the shell will now that it needs to execute this file using Python. Read more... Shebang (Unix)

Related

redirect django runserver output in order to debug with pudb

I'm currently trying to use pudb to troubleshoot a django application.
In order to do so, I'm running the runserver instead of gunicorn.
Then, when I want to debug, I added:
import pudb; pu.db
The pudb gui shows up correctly but is quickly garbled by the runserver output.
As per pudb documentation, I can avoid this by setting the PUDB_TTY variable before starting the server.
$ tty
/dev/pts/3
$ PUDB_TTY=/dev/pts/3 manage.py ... runserver ...
Unfortunately, the GUI still gets garbled by the output of the server.
Alternatively, I tried to redirect all output from the runserver (>/dev/null 2>&1), but the pudb output also get caught (obviously).
Is there a way to:
have the runserver not produce any output?
tweak pudb ?
It looks like the TTY redirect feature is only available in the Development branch
I was able to get it to work with:
$> git clone https://github.com/inducer/pudb
$> cd pudb
$> python setup.py install
In terminal 1:
$> tty
# Outputs: /dev/pts/5
$> perl -MPOSIX -e pause
In terminal 2:
$> PUDB_TTY=/dev/pts5 python manage.py runserver

run manage.py where manage.py is not present?

manage.py is under project_home/mysite/mysite/bin/manage.py
I did it following a recommendation from some book.
The point is it's rather hard to execute python manage.py something as it stands since I have to move to the directory or type the directory path leading to it.
Is there a convenient way to call manage.py in this setup?
If you want to call manage.py anywhere, you can use Django-manage.py-anywhere. As package description says you can run manage.py commands from any directory of your Django project.
See more here: https://github.com/timonweb/Django-manage.py-anywhere

Django runserver error when specifying port

I have recently become accustomed to doing the following in my django projects so that I can test bowser compatibility on various OS (i.e. non-linux):
$ sudo ./manage.py runserver 0.0.0.0:80
This allows me to access the project through any machine on the network.
However, I just setup a new machine and this command issues the following error:
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
I understand that django is having trouble finding the module, what I don't understand is that plain old:
$ sudo ./manage.py runserver
Runs fine. All I am doing here is changing the port, surely? And, of course, it worked fine in the past.
N.B.
1. I am using Django 1.4
2. I have tried within a virtualenv and on system and I get the same result.
3. I do not have django installed system wide (just in virtualenvs)
Any help would be much appreciated.
I guess the sudo command will run the process in the superuser context, and the superuser context lack virtualenv settings.
You may try to call the python binary at your virtualenv explicitly, for example:
sudo $(which python) manage.py runserver 0.0.0.0:80
Make a shell script to set the virtualenv and call manage.py runserver, then sudo this script instead.
#!/bin/bash
source /home/darwin/.virtualenvs/foo/bin/activate
cd /path/to/project/foo
python manage.py runserver 0.0.0.0:80
Replace /home/darwin/.virtualenvs/foo with the root of your actual virtualenv and /path/to/project/foo with the root of your project.
Here's another solution, instead of creating shell script, just specify which python executable you want to use in the command:
Assuming that your virtualenv container is called .virtualenvs and there's an env called myproject in it, this is command you have to write:
$ sudo ~/.virtualenvs/myproject/bin/python manage.py runserver 0.0.0.0:80
Building upon #Paulo_Scardine's anwser:
If you want to keep your virtualenv environment variables, you can add the -E option to the sudo command:
sudo -E $(which python) manage.py runserver 0.0.0.0:80
Here's another solution, instead of creating shell script, just specify which python executable you want to use in the command:
Assuming that your virtualenv container is called venv in your project home directory, this is command you have to write:
sudo /home/mahome/PycharmProjects/sampleproject/venv/bin/python manage.py runserver 127.0.1.1:80
Run
manage.py runserver 0.0.0.0:8000
ie. run the server in different port and not the default port 80
while accessing the url use the port number

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.

south django migrate

I installed south and I try to use it to migrate now:
./manage.py schemamigration myapp --initial
I get a :
-bash: ./manage.py: Permission denied
and if I sudo I get:
sudo: ./manage.py: command not found
Response.
Whats wrong?
Thanks!
Your manage.py isn't executable. Simply pass it to the interpreter instead.
python manage.py ...
You could also make it executable:
sudo chmod u+x
So you can run it like ./manage.py