Forums

Django runserver on pythonanywhere?

Hi,

Can I run Django's runserver on Pythonanywhere somehow?

From Bash console, I started it with python manage.py runserver 0.0.0.0:8001 But I cannot access it at http://myusername.pythonanywhere.com:8001

My intention is to use PythonAnywhere to serve me as development server as well as production sever.

I'd like to use pdb to debug view functions interactively after it was called for POST. I am using logging to get message displayed in error log. But I miss interactivity of pdb. "manage.py shell" gives me interactivity for debugging models but not views with request context.

Googling around, it looks it is difficult to get console access for WSGI app... https://code.google.com/p/modwsgi/wiki/DebuggingTechniques https://github.com/GrahamDumpleton/wsgi-shell

So I would like to use django's runserver.

(Would SSH port forwarding make this work?)

SSH port forwarding might work, yes. Be aware that the ports on PythonAnywhere are effectively public, so anyone can snoop on what you're doing. But, assuming that doesn't matter, then you could try using SSH port forwarding. Something like this:

ssh -L 8002:localhost:8001  aerialist@ssh.pythonanywhere.com

Would set up port 8002 on your machine to be hooked up to port 8001 on PA. I think.

SSH port forwarding works! Thank you, harry!

what 's the password in here

your SSH password is the same as your normal account password, but SSH is a paid feature I'm afraid...

When I execute the command "python manage.py runserver 0.0.0.0:8001" via SSH as mentioned above, the server starts successfully and displays the following output:

System check identified 14 issues (0 silenced). January 25, 2024 - 23:25:22 Django version 4.2, using settings 'settings' Starting development server at http://0.0.0.0:8001/ Quit the server with CONTROL-C.

the 'runserver' command itself appears to be running without any issues. However, I cannot access it at http://myusername.pythonanywhere.com:8001 and http://appsname-myusername.pythonanywhere.com:8001. The website shows the following message:

"This site can't be reached. The response time from myusername.pythonanywhere.com is too long. Please try the following:

Check your internet connection. Verify your proxy and firewall settings. Run the Windows Network Diagnostics tool. ERR_CONNECTION_TIMED_OUT"

If you have any insights or solutions, please share. I appreciate any assistance in resolving this issue.

That is correct. We do not route traffic to arbitrary ports. If you want to run Django, you need to use a web app.

Is it not possible with Google Chrome? Please provide an explanation about web apps. It would be appreciated if you could also share any links that contain relevant information.

Hope fully this page can help - https://help.pythonanywhere.com/pages/DeployExistingDjangoProject/

So to conclude, while I can execute runserver in PythonAnywhere and it runs successfully, but I cannot view my application on the web interface, correct? I understand that I need to set up my application as a web app within PythonAnywhere's environment.

Yes, that's exactly right. You could potentially use runserver as a sanity-check to make sure that there are no syntax errors in your code, but the server that it runs will not be accessible from anywhere. So in order to view your Django site, you need to set it up on the "Web" page.