Until now this is how I use to develop and deploy (update) code on PythonAnyWhere server.
[alias] xpush = !git push $1 $2 && /home/rana/project-dir/reload.shNow instead of running git push origin repo-name , you will run git xpush origin repo-name command. Every-time you push your code, reload.sh file is executed. Now in reload.sh file we write our code which will pull the code on PythonAnyWhere server and reload the web app. Write below code in reload.sh file and save it. Make this file executable.
#!/bin/bash sshpass -p paw-password-here ssh email@example.com '/home/user/project-dir/remote.sh'For this to work you need to install sshpass in your system or you may enable passwordless login. So above line in reload.sh file makes an ssh connection to PythonAnyWhere server and executes a shell script located on remote server. Shell Script on PAW server:
#!/bin/bash echo "Starting git pull. Author - Anurag Rana" cd /home/user/mysite git pull upstream remote-repo touch /var/www/www_mysite_com_wsgi.pyCreate a file at location /home/user/project-dir/remote.sh . Make this file executable. Remember in first step above we added one more git remote named upstream. In the 4th line of above script we are pulling code from same remote URL without using password (because we are using ssh keys and this remote is created with SSH URL). Now reloading the web app is done in 5th line of above script. This works because the server process that handles your web application is watching that file and restarts itself whenever it is modified. Testing: Now when all the above tasks are completed, lets test the application.
rana@Brahma: mysite$ git xpush origin mysite Password for 'https://firstname.lastname@example.org': Counting objects: 8, done. Delta compression using up to 4 threads. Compressing objects: 100% (7/7), done. Writing objects: 100% (8/8), 593 bytes | 0 bytes/s, done. Total 8 (delta 6), reused 0 (delta 0) To https://email@example.com/anurag8989/mysite.git 53e8a3a..aeaa9fe mysite -> mysite <<<<<<:>~ PythonAnywhere SSH. Help @ https://help.pythonanywhere.com/pages/SSHAccess Starting git pull. Author - Anurag Rana From bitbucket.org:anurag8989/mysite * branch mysite -> FETCH_HEAD 53e8a3a..aeaa9fe mysite -> upstream/mysite Updating 53e8a3a..aeaa9fe Fast-forward mysite/app1/templates/app1/header.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)If something is not working, check if your shell script files are executable and are placed at right path. If you are stuck at any step, feel free to comment. Host your Django project for free on PythonAnyWhere.