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
  • 431

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
  • I am so lazy so trying to avoid ./ too. :) – wbad Oct 18 '13 at 10:29
  • Isn't there a way to ditch ./ ? – wbad Oct 18 '13 at 10:42
  • 4
    You're approaching this from the wrong angle. Any decent shell will support autocompletion by hitting the tab key. Telling the shell you want to limit your autocompletion choices to the current directory by using ./ is a good thing and makes it much faster to complete the filename you were looking for. In the case of Django's manage.py file I type './m' and hit tab. Boom. – eagleflo Oct 18 '13 at 10:48
  • @wbad check my answer which is for the lazy. – don.joey Oct 23 '13 at 14:08
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,236
  • 4
  • 48
  • 98
Naive
  • 4,825
  • 11
  • 27
  • 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,753
  • 5
  • 26
  • 43
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
  • 28,662
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,264
  • 56
  • 94
  • 147
-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