Local Django website won't load in browser - django

I'm guessing there's a very simple solution to this, but I searched every forum and setup guide and can't figure it out:
I built a Django/CentOS-6.3 environment on my local server (using VirtualBox and Vagrant). When I startup my server in the vagrant terminal with 'python manage.py runserver [::]:8000' it starts up with no errors.
Validating models...
0 errors found
May 31, 2013 - 13:56:15
Django version 1.5.1, using settings 'mysitename.settings'
Development server is running at http://[::]:8000/
Quit the server with CONTROL-C.
However, when I try to navigate to 'http://127.0.0.1:8001' in my browser (I set up port forwarding from port 8000 to port 8001 in my Vagrantfile), the browser just hangs for 5 minutes until it times out, then it returns the message:
> The connection was reset
> The connection to the server was reset while the page was loading.
> ...
This is the exact same message I get from the browser even after I shut down my local server. My computer obviously recognizes this as a forwarded port, because any other port I try (such as 8000) instantly returns an error saying that it can't establish a connection to the server at 127.0.0.1:8000.
With regard to the server files, I have done many similar setups with Django/Ubuntu in the past and have never had any issues, but there must be something different about Django/CentOS that is causing this to happen (or maybe I made a mistake someone in one of my server files). I have followed guides for setting up Django & PostgreSQL on CentOS, too, but to no avail. I'll comment some of the files I have created/edited below.
If anyone has a solution, or even has advice on where to start looking for errors, I would very much appreciate it.

If your network is configured correctly and your django application with
python manage.py runserver 0.0.0.0:8000
and you still can't access your django app from the VM host there is almost certainly a firewall issue. The solution above is good if you are running iptables.
I deployed CentOS 7 on a virtualbox VM from a Windows 7 host. I didn't know that this distribution uses firewalld, not iptables to control access.
if
ps -ae | grep firewall
returns something like
602 ? 00:00:00 firewalld
your system is running firewalld, not iptables. They do not run together.
To correct you VM so you can access your django site from the host use the commands:
firewall-cmd --zone=public --add-port=8000/tcp --permanent
firewall-cmd --reload
Many thanks to pablo v for pointing this out in the post "Access django server on virtual Machine".

the host's "127.0.0.1" is not the same as the guest's "127.0.0.1". Per default the command
python manage.py runserver
listens only to the guest's localhost. You should be able to test it from within the vm (use "vagrant ssh" to login) and run
curl -I http://127.0.0.1:8000/
The host as a different IP. To access the development server from the host you have to start it without ip restriction:
python manage.py runserver 0.0.0.0:8000
Yes:
python manage.py runserver [::]:8000
should be the same. But that's IPv6 syntax AFAIK. Are you sure that the "manage.py runserver" command supports IPv6 by default? I've never used ipv6 addresses w/ django, but looking at the source (https://github.com/django/django/blob/master/django/core/management/commands/runserver.py) there seams to be a flag that the default to False ("--ipv6"). Perhaps that's the "real" problem?
Regards,

For a similar problem,
This command worked like a charm for me
python manage.py runserver [::]:8001

Check your iptables, and stop it. Ubuntu commonly does not open the iptables when it starts.

Related

django app not being served on digitalocean droplet

I'm following this tutorial online https://simpleisbetterthancomplex.com/tutorial/2016/10/14/how-to-deploy-to-digital-ocean.html
I get to an intermediary step where I want to check if I can access the app on the IP address. I run python manage.py runserver 0.0.0.0:8000 which returns the following:
System check identified no issues (0 silenced).
November 22, 2018 - 17:41:08
Django version 2.1.3, using settings 'mysite.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
So no errors. Then I navigate to my_droplet_ip:8000 and I get a timeout. "took to long to respond."
I am running the runserver command from a user rather than root. Don't know if that matters...
Any idea what's going on here?
I had to expose the port 8000 by running the command sudo ufw allow 8080. Wasn't mentioned anywhere in the tutorial...

Issues with accessing Django app on remote server; manually assigning IP address does not work [duplicate]

This is probably a very basic question. I SSH to my virtual Ubuntu server and start a django webserver running on localhost:
Downloading/unpacking django
Downloading Django-1.9.5-py2.py3-none-any.whl (6.6MB): 6.6MB downloaded
Installing collected packages: django
Successfully installed django
Cleaning up...
Performing system checks...
System check identified no issues (0 silenced).
You have unapplied migrations; your app may not work properly until they are applied.
Run 'python manage.py migrate' to apply them.
April 13, 2016 - 14:16:19
Django version 1.9.5, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
The Ubuntu server has a static IP [x.xxx.xxx.xxx] so from another machine on another network I try to access the above website in a browser using that static IP address:
x.xxx.xxx.xxx:8000
But I get:
This site can’t be reached
x.xxx.xxx.xxx refused to connect.
ERR_CONNECTION_REFUSED
So I assume that I cannot access the website like this and that is only available on the host it self even though the host has an external/static IP address?
Edit:
The answer is also in:
https://docs.djangoproject.com/en/1.9/intro/tutorial01/#the-development-server
python manage.py runserver 0.0.0.0:8000
You need to run your web server on 0.0.0.0:8000, then externally you would use either ip or host name to access. Using 0.0.0.0 means the django service would listen to all configured network interfaces.
Check wikipedia on details about 0.0.0.0.
Another answer on serverfault could be helpful.

django tutorial returns 'ERR_EMPTY_RESPONSE'

I'm following the django tutorial: version 1.8, Ubuntu 10.04, python 3.4 in a virtual environment. I seem to create a django project (yatest) on my Ubuntu server just fine and I start the development server:
(v1)cj#drop1:~/www/yatest$ python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
August 09, 2015 - 04:37:33
Django version 1.8.3, using settings 'yatest.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
but when I browse to http://myserver:8000 all I get in response is 'ERR_EMPTY_RESPONSE'.
This is the first part of the tutorial before an app is even created. At this early stage in the tutorial it doesn't mention any error log I can check. My telnet client doesn't say anything crashed, and 'ctl-c' will shutdown the server process with no complaints.
Using netstat -lntp I verified no other processes are using port 8000. I do not have Apache installed. I do have gunicorn and nginx installed but both are stopped and not in use yet in the tutorial.
I'm rather new to linux; I could use some help finding an error log or other debugging tools to solve this. I don't doubt I've missed some basic OS setting or something to enable TCP access, etc..
Thanks
Clark
Found my mistake. When starting a dev django server on dedicated server one MUST include the dedicated server's address in the command. This is not needed when launching a dev server on the same machine as your browser. So instead of
$python manage.py runserver
you have to run
$python manage.py runserver <server ip>:8000.
So this is my inglorious start on stack exchange. You saw nothing! :P
If you're running natively in an virtual envrionment, then you need to specify a port and address:
python manage.py runserver 127.0.0.1:8000
For containers, it's easiest to listen to all addresses:
python manage.py runserver 0.0.0.0:8000
For anybody using PyCharm in a docker environment, it's also worth knowing that PyCharm will override your docker-compose configuration to change the runserver command to bind to the port specified in the Host option in your Run/Debug Configurations window.
Make sure you set the Host to 0.0.0.0 and the port to 8000 if you want to use the debugger etc.
If you don't want the trouble to determine server ip (ie when you're using containers), you can listen to 0.0.0.0:8000
python manage.py runserver 0.0.0.0:8000

EC2 instance can not access in browser

I created one EC2 instance for Django project with Ubuntu server.
I installed all required package of django, python etc successfully.
But when I am trying through ssh with private ip : python manage.py runserver xxx.xx.xx.xx:8983 its running, but when I am trying to load it through browser its gives as error : "The Connecion has timed out"
I have assigned VPC security group to this instance.
Also, I try with public IP address through SSH: : python manage.py runserver XXX.XX.XX.XX:8983
It gave error as follows :
Validating models...
0 errors found
July 15, 2015 - 22:34:10
Django version 1.6.7, using settings 'conf.settings.local'
Starting development server at http://xx.xx.xxx.xx:8983/
Quit the server with CONTROL-C.
Error: That IP address can't be assigned-to.
And same error occurred when I run in browser.
I also tried following both options but no luck
0:8000
0.0.0.0:8000 port running successfully in ssh with python manage.py but not in browser.
I checked /etc/network/interfaces this file, following lines already exists there:
auto lo
iface lo inet loopback
Anybody has any other solution?
Daya,
I try run with port 0:8000 0.0.0.0:8000 but no use.
Also, /etc/network/interfaces file was perfect.
But In my case, solution for this problem was to change script file's location.
I mean to say my django application folder location was /home/ubuntu
but when I move it to /Var/www it worked.It worked because server is apache2.

How to view the webpage in Django tutorial on Linode server

I know I have similar question with this post: Django tutorial on remote server: how to view in my browser? But I just can't solve it with the answer it has.
I am playing with Django framework now. I am trying to do the Django tutorial on my Linode server. Everything works fine, but when we have to examine the webpage we have, the tutorial says that we have to check http://127.0.0.1:8000/ on the server. I only have command line access on the Linode server, so I don't know how to see that webpage on the linode from my desktop. I tried to use the command like python manage.py runserver 123.123.123.123:8000 and set the ip to my Linode server, but I still can't access that webpage from my desktop (I do remove the firewall for 8000 port). Does anyone know how can I check the change for the remote webpage I created within Django framework on the Linode server? Thanks.
Just to make sure, are you trying to access the following URL in your browser (where the server ip address is 123.123.123.123)?
http://123.123.123.123:8000
Secondly, are you able to telnet to port 8000, to make sure you have correctly opened the port on the firewall.
I had this problem too and I wanted to clarify what I did for others who might get stuck:
First, remove the firewall for port 8000
sudo nano /etc/iptables.firewall.rules
-A INPUT -p tcp --dport 8000 -j ACCEPT
Second, reboot the linode
Third, restart the development server
cd /home/mycode/mysite
python manage.py runserver 123.123.123.123:8000
(where you use your ip)