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
0

6 Answers 6

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.

4
  • I am so lazy so trying to avoid ./ too. :)
    – wbad
    Oct 18, 2013 at 10:29
  • Isn't there a way to ditch ./ ?
    – wbad
    Oct 18, 2013 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, 2013 at 10:48
  • @wbad check my answer which is for the lazy.
    – don.joey
    Oct 23, 2013 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
0
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.

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.

0

set .zshrc and add this:

alias -s py=python

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

1
  • Thanks @David Foerster, this my first answer in askubuntu.
    – michael Ma
    Nov 22, 2017 at 6:37
-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.

Not the answer you're looking for? Browse other questions tagged .