How to fix the connection error in django - python

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.

Related

Can't connect to django application running on AWS Ubuntu EC2

I am runnig my Django application on AWS EC2 t2.micro with Ubuntu. I've successfuly installed all modules, created a PostgreSQL database, and made all migrations. Now when I'm running python manage.py runserver 172.31.27.208:8000 I can't connect to it in browser, getting ERR_CONNECTION_TIMED_OUT error.
python manage.py runserver 172.31.27.208:8000 returns:
System check identified no issues (0 silenced).
January 30, 2020 - 11:10:59
Django version 3.0.2, using settings 'project_test.settings'
Starting development server at http://172.31.27.208:8000/
Quit the server with CONTROL-C.
So I assume the server running properly.
I am using private ip form ec2 console which, I've checked, is matching to the ip adress returning by running command ifconfig.
TCP port is opened in AWS security_group inbound rules on port 8000.
I've also checked netstat -lan after running django server, it shows:
tcp 0 0 172.31.27.208:8000 0.0.0.0:* LISTEN
I have been looking for same issues and everything listed in them seems to be correct in my case. Since that I have no idea what is going wrong. Can provide more information if you need something. Will appriciate any help. Thank you.

Can't start server in openshift

I have deployed django with quick start.
When I try to start django-server with python manage.py runserver in SSH-Terminal, I get following error:
Performing system checks...
System check identified no issues (0 silenced).
October 04, 2015 - 20:56:45
Django version 1.8.2, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Error: You don't have permission to access that port.
How can I start the django-server successfully?
You seem to have a few things that you are doing that are probably causing the issues that you are encountering.
You should not use the runserver command to start the server in a
production environment, that is only to run a local server for
development purposes.
You can't start a server on port 8000 on openshift, you need to
start it on port 8080, see:
https://developers.openshift.com/en/managing-port-binding-routing.html
The current version of the django quickstart (#464680f on Sep
9) is not working properly, you can use this repo for the moment:
https://github.com/jsvgoncalves/django-openshift
Edit: The bug reported in 3. was fixed here: https://bugzilla.redhat.com/show_bug.cgi?id=1308722
Also, as per the README.md of that repo, you should set the $OPENSHIFT_PYTHON_WSGI_APPLICATION environment variable to the path of wsgi.py.

Django tutorial: problems accessing development server

I am going through the Django tutorial and am running into problems when trying to view my webpage. I am at the very beginning of the tutorial when I first run the command python manage.py runserver xxx.xxx.xxx.xxx:8000 (replace the x's with my remote server's IP). When I try to navigate to http://xxx.xxx.xxx.xxx:8000 on my local machine, Chrome gives me the error ERR_CONNECTION_REFUSED. I have also tried running the server on 0.0.0.0:8000 and the same issue persists. The port is definitely open and there are no firewalls blocking it - when I plug in my IP and 8000 into this site it claims it is open: http://ping.eu/port-chk/.
I get no error messages on my console from the Django side of things. What could be causing this error? I really don't know much about servers or ports. Thanks in advance.
I am on a virtual Linux server running CentOS 6.4. My local machine is running Mac OS 10.9.5
EDIT:
When I run netstat --listen, port 8000 doesn't show up in the Local Address column, even though my Django dev server claims to be running. Someone mentioned to me that this means my application is not listening on this port. What does this mean and how do I remedy it?
EDIT:
I can access the page through my phone's internet with no issues. What gives?
If you're running Django inside a VM but accessing it from the host Mac, you'll need to forward the port. See the settings in Virtualbox/VMWare/whatever.
Note however that Django runs perfectly well directly on a Mac, so if you're just learning it may be simpler to just install it there.
Don't issue no IP, runserver will tell you where you can connect to when launching it.
Since you're launching it from your VM, you might supply the IP.
Ensure system level routing is okay.
Add your host local IP to the ALLOWED_HOSTS setting.

Accessing django project in LAN systems

I used django and developed a site which is working fine, and its about to move to production and ready for deployment in a couple of weeks.
So before moving to production, i want to share the site with some of my employees to check the functionality and something else. Actually their systems are connected in LAN with mine.
So my system IP address is something like 192.168.12.135, when we run run django development server its runs at localhost:8000, i mean with the system IP address and with a port 8000 like 192.168.12.135:8000 right.
So i had shared them the project site link as 192.168.12.135:8000, but when they tried on the systems which are connected in LAN, it is not accessible and displaying an error Server not found.
I tried the above same way because recently i used python web.py framework and developed a minimal site , and when we run the server, it by default runs as localhost:8080 , and when i accessed this link from others system that are connected in LAN with mine as 192.168.12.135:8000 , its working fine and is accessible.
So can anyone please let me know
1. How to access the site on the systems that are connected in LAN before moving to production(in some real servers like apache, nginx etc.,).
2. Basically i am new to web developing and this is my first site developed in python, so
i don't know more about servers and deploying a project. So can anyone please let me know
the detailed information about deploying django on different servers
(First of all i am looking for a solution for 1st problem(Accessing in LAN before moving to
production))
If you run
python manage.py runserver 0.0.0.0:8000
your development server will be available on port 8000 to anyone on your LAN and on localhost as well (and it does not depend on your ip address)
You need to explicitly tell the development server to run on your IP rather than localhost.
Try python manage.py runserver your_ip:port.
Though it'll be accessible if you're running through apache or any other webservers other than the development server.
And to your 1st question, I would advice you to host and use a local apache server rather than using development server. Doing so, you can foresee the issues you'll be facing when moving to production.
And to 2nd, there are plenty of resources available configuring Django with different servers. Hail Google. :)
In your settings.py change ALLOWED_HOSTS to
ALLOWED_HOSTS = ['*']
Run your server by entering the following command
python manage.py runserver 0.0.0.0:8000
In order to access the project from another device enter the IP address of the server followed by the port number, which is 8000 in this example.
On windows I did everything you said but one thing was missing at my end to connect through Wi-Fi..
In settings.py:
ALLOWED_HOST = ['*']
Put Network profil in Private mode:
Windows > Settings > Network & Internet > Wi-Fi > (Click on_your_network) > In Network profil select: Private
Exemple: Run your server on the port 8000:
python manage.py runserver 0.0.0.0:8000
Then to access to the server with your other devices connected to the same network, enter the IPv4's server address with the your port (here 8000)
Exemple, if the IPv4's server address is 192.168.20.26 put the folling text directly in your browser:
192.168.20.26:8000

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