Django server is not working on Virtual Server - python

I have a server that is using Ubuntu. I have uploaded my Django project to the server. And ran the command:
python manage.py runserver 0.0.0.0:80
But when I try to go the website in browser I get The requested URL could not be retrieved error.
What can be the reason of that?

python manage.py runserver {YOUR_PUBLIC_IP}:80
Also you need to check firewall settings, make sure that 80 port is opened

Related

How to Django remote access to server using Windows

I'm starting the tango-with-django tutorial.
And I'm trying to access the created website using other computer. Both computers are using Windows OS. And this is not working.
$ python manage.py runserver <your_machines_ip_address>:5555
I'm using the IPv4 Adress that I get when I type:
$ ipconfig
What am I doing wrong or what is missing?
Download ngrok from here: https://ngrok.com/ (this will allow you to serve your web app to anyone on the Internet)
Start your Django project normally or provide any port number.
python manage.py runserver
If you are running windows, open a command prompt and browse to the location where the ngrok binary is located.
If you are running GNU/Linux / OSX, just open a terminal.
Then run the following command.
ngrok 8000
Replace 8000 by whichever port the Django project is running on.
ngrok will give you a public hostname like http://abc.ngrok.com
Anyone you give this address to will be able to view / interact with your Django application anywhere on the Internet.
Update: Newer versions of ngrok need to be run like this: ngrok http 8000
Try python manage.py runserver 0.0.0.0:5555. And access it on the other machine using http://<your-ip-address>:5555. That should work

c9.io Error: You don't have permission to access that port

So i was doing a django tutorial this weekend using the Cloud9 IDE on their web app c9.io. All is good and dandy until i get to the piece of running the server python manage.py runserver
You would think that it would work fine but i keep on getting this stuff.
python manage.py runserver
Validating models...
0 errors found
February 22, 2014 - 23:42:03
Django version 1.5, using settings 'djangotut.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Cloud9 Your application is running at https://djangotut-c9-diaz994.c9.io
Cloud9 Error: you may be using the wrong PORT & HOST for your server app
use './manage.py runserver $IP:$PORT' to run your Django application
**Error: You don't have permission to access that port.**
I do not know why it is not allowing me to run this. It seems like it starts the server and then it kills it. Have any of you had experience with this on the c9.io site? Thanks alot.
They don't allow access to the standard ports that django wants to use, but they do provide the appropriate ports in the form of environment variables. Use this instead:
python manage.py runserver $IP:$PORT
That should work.
Yes, thats right. First use
python manage.py runserver $IP:$PORT
to start the development server and than don't forget to add allowed hosts to your settings.py
ALLOWED_HOSTS = ['<your_project_name>.c9users.io']

How do I access my django app running on Amazon ec2?

So, I have looked around stack overflow + other sites, but havent been able to solve this problem: hence posting this question!
I have recently started learning django... and am now trying to run it on ec2.
I have an ec2 instance of this format: ec2-xx-xxx-xx-xxx.us-west-2.compute.amazonaws.com on which I have a django app running. I changed the security group of this instance to allow http port 80 connections.
I did try to run it the django app the following ways: python manage.py runserver 0.0.0.0:8000 and python manage.py runserver ec2-xx-xxx-xx-xxx.us-west-2.compute.amazonaws.com:8000 and that doesnt seem to be helping either!
To make sure that there is nothing faulty from django's side, I opened another terminal window and ssh'ed into the instance and did a curl GET request to localhost:8000/admin which went through successfully.
Where am I going wrong? Will appreciate any help!
You are running the app on port 8000, when that port isn't open on the instance (you only opened port 80).
So either close port 80 and open port 8000 from the security group, or run your app on port 80.
Running any application on a port that is less than 1024 requires root privileges; so if you try to do python manage.py runserver 0.0.0.0:80 as a normal user, you'll get an error.
Instead of doing sudo python manage.py runserver 0.0.0.0:80, you have a few options:
Run a pre-configured AMI image for django (like this one from bitnami).
Configure a front end server to listen on port 80, and then proxy requests to your django application. The common stack here is nginx + gunicorn + supervisor, and this blog post explains how to set that up (along with a virtual environment which is always a good habit to get into).
Make sure to include your IPv4 Public IP address in the ALLOWED_HOSTS section in Django project/app/settings.py script...

Can't get basic Django setup working on VPS

I'm trying to deploy a Django website on a VPS (CentOS) and I'm running into problem right from start. Here is what I've done:
ssh root#myserver.com
cd /home/mydomain/public_html
pip install django
django-admin.py startproject mysite
cd mysite
python manage.py runserver 0.0.0.0:8000
When I visit mydomain.com:8000 I expect to see the initial Django page "It worked!". But instead the browser just hangs and the connection times out.
Is there something I'm missing here?
If you cannot reach the site try the following:
$ wget http://127.0.0.1:8000
If you get a response locally but not through the network it could be a firewall or iptables issue. CentOS comes fairly locked down so check the ip tables.
http://wiki.centos.org/HowTos/Network/IPTables#head-cdc2ff6985016368c04d0b37a5914eef2e8d5796

python manage.py runserver not work

I am trying to learn django on my mac by following along with Writing your first Django app
I run
django-admin.py startproject mysite
and it creates the files it should. Then I try to start the server by running
python manage.py runserver 8080
It's OK,the message is :
Validating models...
0 errors found Django version 1.4.2, using settings 'mysite.settings'
Development server is running at http:// 127.0.0.1:8080/ Quit the
server with CONTROL-C.
But I when I visit the 127.0.0.1:8080, I get a 504 error page:
This Page Cannot Be Displayed
The system cannot communicate with the external server ( 127.0.0.1 ).
The Internet server may be busy, may be permanently down, or may be
unreachable because of network problems. ......
What am I missing here?
Considering you are using a proxy (as mentioned in the comments). The reason for this error:
This Page Cannot Be Displayed
The system cannot communicate with the external server ( 127.0.0.1 ). The Internet server may be busy, may be permanently down, or may be unreachable because of network problems. ......
is that 127.0.0.1 is looked up at the proxy and on the proxy server there is nothing listening on port 8080
Use 'python manage.py runserver 8000' instead of 'python manage.py runserver 8080'
Worked for me.

Categories