Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
share|improve this question
    
possible duplicate of run python in terminal –  Eliah Kagan Sep 10 at 0:39

5 Answers 5

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.

share|improve this answer
    
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

Try to create an alias in your bashrc file like
alias python='p'
after that execute it using
p manage.py runserver

share|improve this answer
1  
Please elaborate on your answer. –  guntbert Oct 18 '13 at 14:15

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.

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.