python manage.py runserver not work - python

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.

Related

Django server is not working on Virtual Server

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

How to fix the connection error in django

I have created a new project in django. when I run python manage.py runserver, I am getting the msg in command prompt like below.
/var/www/samplepro/myapp$ python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
March 26, 2015 - 10:52:31
Django version 1.7.7, using settings 'myapp.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
when I test in browser, I am getting the page can't be displayed error. Can anyone help me to do get the django page.
You stated that you are running the server on Ubuntu while you are trying to connect it from another PC running Windows. In that case, you should replace the 127.0.0.1 with the actual IP address of Ubuntu server (the one you use for PuTTY).
I am also developing in a virtual machine.
Use ifconfig to figure out the IP address that has been assigned to your virtual machine.
Then start the server with:
python manage.py runserver <IP>:8000
Of course you could also use a different port instead of 8000. Then use that address and port in your host browser to access your server.
Note: At least in my VM, the virtual machine gets a new address from time to time, so check that in case you have trouble starting your server with the same command.
If this does not help, check your hosts file as mentioned in one of the comments.

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 Django to server its dev server on my LAN

I really try not to ask questions on here, but I've been googling for a bit now and can't find the answer or another method to try. I have a CentOS box at my house hooked to a router. I've assigned it a static IP of 192.168.1.140. Because I'm lazy, I just ssh into it. When I'm goofing around with Django (learning Django/Python at the moment) and I run python manage.py runserver with a variety of IP address, I can't get my browser to access that box. I've tried
python manage.py runserver 0.0.0.0:8000
python manage.py runserver 8000
python manage.py runserver localhost:8000
python manage.py runserver 192.168.1.140:8000
python manage.py runserver 192.168.1.255:8000
python manage.py runserver 192.168.1.0:8000
python manage.py runserver 192.168.1.1:8000 #this errors out and says I can't use this IP address although this is the IP I use to access the router
When I run netstat -tln in another terminal I can indeed verify that it's listening on port 8000 to the specified address. In iptables I've run it just how it is and I've run it through tcp --dport 8000 and --sport 8000 with the same results. Just can't quite seem to crack the code. I've also setup port forwarding on my router so port 8000 is directed at 140. Is there a log somewhere I can check that I can't find on google? What am I missing?
Whilst googling I came close to an answer but I think it must be something else.
I'm running Python 2.7.5 and Django 1.5.2 through virtualenv if you need to know. Is virtualenv my issue? Thanks y'all
According to this documentation,
the right approach would be to set the python manage.py runserver xxx.xxx.xxx.xxx:yyyy to the IP address of the port you're using [Wi-Fi or Ethernet].
If the other devices are connected to the same LAN, then they should be able to access your Python VirtualEnv straight from their browsers.
Worked just fine on mine.
Also, I use DHCP - don't know if it changes anything. Just thought I'd mention that.

Categories