1

I am experimenting with Django develpment in virtualenv. It is rather anyoing that each time I should type commands like:

python manage.py runserver

I am wondering what should I do to run the same command without 'python', i.e. just:

manage.py runserver
wbad
  • 461

6 Answers6

4

You can set the file to be executable with chmod +x manage.py and then execute it with ./manage.py runserver.

Note that if you create your own script files you will have to include the UNIX shebang in the file.

eagleflo
  • 256
2

Try to create an alias in your bashrc file like

alias python='p'

after that execute it using

p manage.py runserver

or

Copy manage.py to /usr/bin/ directory and execute like this

manage.py runserver
wjandrea
  • 14,504
Naive
  • 4,895
  • 11
  • 28
  • 35
1

If you really must do away with the ./ there is a way.

There are certain paths that python will look to run a file.

Place a file in usr/local/bin and make sure it is executable. Then you can run it by just typing the name. That is because usr/local/bin is a directory that Python check for executables.

Thats the extent of my knowledge. For more useful info you will want to figure out how to view the PYTHONPATH variable so you know what directories this works for. Also there is a way to add a directory to this variable so you can add a directory with all your py scripts.

I don't know how to do this off the top of my head, and I'm sure you can Google as well as I can.

Dan
  • 6,784
1

I use the following django related aliases in order to type less:

alias pm='python manage.py'
alias rs='python manage.py runserver'
alias goprojectname ="workon projectname; cdvirtualenv; cd projectfolder; rs"

You can put them in your .bashrc or .bash_aliases (preferably). I can just type rs to get runserver working or, for instance, pm syncdb to sync the database.

Here is how to create permanent aliases.

don.joey
  • 29,392
0

set .zshrc and add this:

alias -s py=python

when you type somefile.py, use python open it <=> python somefile.py.

David Foerster
  • 36,890
  • 56
  • 97
  • 151
-1

A lazy trick - just add #/usr/lib/python on the first line of your Python app, and make it executable using the chmod trick above, and double click it and it should work, or in the terminal,
./manage.py runserver
Hope this helps.

user27731
  • 461
  • 2
  • 7