How to view the webpage in Django tutorial on Linode server - django

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)

Related

How to host a django website in my pc and view it in another pc?

I have a django project in my pc.
In terminal I've run python3 manage.py runserver <my ipaddress>:8001
When I try to open the link in another pc, it is showing error page which says:
Invalid HTTP_HOST header: '<my ipaddress>:8001'. You may need to add '<my ipaddress>' to ALLOWED_HOSTS.
What should I do?
And moreover is it possible to put some text in place of ipaddress in the url?
For example, I want to host it as myproject/ instead of that complex url.
On one condition this will work
if both computers are on the same network like local Hotspot or same
LAN network
steps:
add '*' in your django projects's setting file in Allowed Host it will look like
ALLOWED_HOSTS = ['*']
run your server on this ip 0.0.0.0 and port any like 8000 using this command
manage.py runserver 0.0.0.0:8000
run ifconfig if you are using linux ipconfig if windows then you will get your ip address of your server
Open browser in another computer and enter the ip of server shown in 3rd step with port as 8000
http://ip-of-server:8000
Instead of passing <my-ip-address> to the runserver command, pass 0.0.0.0.
If both the machines are in the same network you can run the application on 0.0.0.0 IP address (refers to all IPv4 addresses on the local machine). Refer this link wiki 0.0.0.0 for more details. So, on application server run this:
manage.py runserver 0.0.0.0:8001
Now, from the other machines, access it using http://youripaddresss:8001 , where < youripaddress > is the actual ip address of your machine.
If both computers are not on the same network (local hotspot or LAN network)
You can use ngrok to view whatever is running on your localhost from any device
Using ngrok to view your django project from any device
follow the steps below:
Add '*' in your django projects's setting file in Allowed Hosts:
ALLOWED_HOSTS = ['*']
Download ngrok from the official website
Unzip the downloaded file and then go to the directory where the ngrok file is located via your terminal
Then type the command:
ngrok http 8000
or
./ngrok http 8000
Now you can open the url generated by ngrok on any device to view what is running on your pc:
https://randomly_generated_subdomain.ngrok.io
PS: this can also be used for any webserver running locally, not just django site
ngrok is a great tool that can be used to:
Run personal cloud services from your home
Demo websites without deploying
Build webhook consumers on your dev machine
Test mobile apps connected to your locally running backend
Stable addresses for your connected devices that are deployed in the field
Run your server with this command python manage.py runserver 0.0.0.0:8000
Then you can access your website from any system connected to your wifi with an URL like 192.168.0.1:8000
You may get your IP Address using this command in CMD ipconfig in windows and ifconfig in mac
Also add your IP to ALLOWED_HOSTS in setting.py
ALLOWED_HOST = ['*'] in your settings.py
python manage.py runserver 0.0.0.0:8000
then make sure your machine firewall allows incoming and outgoing traffic.
I use linux machine so from control center go to firewall and allow both incoming and outgoing.
then on your local network machine.
:8000
This is it !
worked for me

Installed "Python-django" on my Virtualbox but not able to access the web pages from host machine web browser

I am pretty new to Web-Development
I have Python-Django and apache2 installed on VirtualBox.The VirtualBox adapter settings are OK since i am able to visit the web pages hoisted from apache2.
Now the problem is when i tried to visit the pages hoisted by django inbuilt web-server
It didn't opened.
For apache2 port number is 80 and for django port number is 8000
Please help me to get through this problem
Django development web server normally binds to localhost (127.0.0.1) only, therefore you can only access it from the same machine (or VM). You can change this behavior by starting it using:
python manage.py runserver 0.0.0.0:8000
This way it will bind to every IP address (both 127.0.0.1 and whatever IP address you gave to your VM) so that you can access it from "outside".

Local Django website won't load in browser

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.

Visit webpage hosted on ubuntu server in a local network

I have a ubuntu server hosting a web page driven by Python Django, I can access that page by using the following command:elinks http:// 127.0.0.1:8000.
Now if I want to access that same web page on a macbook sharing the same home router with my ubuntu server(local ip: 10.0.0.9), how would I do it? Typing in elinks http:// 10.0.0.9:8000 wouldn't work.
Thanks a lot,
ZZ
Are you running the development server using manage.py?
If so, you should start the server using:
python manage.py runserver 0.0.0.0:8000
This will allow the development server to be visited by ips on all interfaces instead of just localhost.
You need to serve it. There are a number of ways to do this, but my preferred method is to use Nginx as a reverse proxy server for gunicorn. This is a good tutorial for that.

Django on SSH public IP

I have Django installed on my SSH-server. But the SSH-server I'm working on, is not at my home. So the local ip-adres Django creates (127.0.0.0:8000) isn't available for me, I can't test my Django-apps graphicly.
What could be a Solution to get it work?
Djano has a command runserver that could set the IP-adres of the server like this:
django-admin.py runserver [IP]:[port]
But which IP I have to fill in there to make it work? The only IP I have is the IP of the SSH-server. Isn't it possible to fill in the IP-address of my webhost(but where I need to give in password etc)?
Thanks a lot!
Choose a publicly available port (say 8000), or redirect an existing web server to use the port you choose, and then start with
django-admin.py runserver 0.0.0.0:8000
Edit
If you happen not to control your available ports, you probably need to hook apache in front of your app. See https://docs.djangoproject.com/en/1.3/howto/deployment/modwsgi/ for info on how to deliver your app with apache and mod_wsgi.
You can try Putty with its tunnels. This program for windows, but I think you can find it for Linux if you use it. I used it to get access to my Postgres databse with pgAdmin with this article. So you can use tunnel for 8000 port and program to get access to it on your local machine.