Django tutorial: problems accessing development server - python

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.

Related

django - Can't connect from remote devices to specific server - connection timed out

I'm aware this question has been asked before but mine is a problem the answers to those questions cannot solve. Whenever I try to access the site through other devices, it just loads forever and then says "this webpage took too long to respond". I have no idea what I am doing wrong.
I've already tried:
Running the command as manage.py runserver 0.0.0.0:8000
Running the command as manage.py runserver 192.168.1.10:8000
Setting ALLOWED_HOSTS to 192.168.1.10
Setting an inbound & outbound rule on the firewall in advanced security
Restarting the computer (because why not)
Downgrading Django to 2.0.0 because I could connect with other devices to a different server running 2.0.0. Didn't work.
And yes, my other devices are definitely on the same network and the local IP address is correct.
I have no idea what else to do. I am able to access the website from my local computer through the local address, but not from other devices. What am I doing wrong?
I'm running Django 2.0.7.
EDIT: I am able to connect to a different server, but for some reason not this one. I checked if it was the difference in versions that mattered but it didn't (that server ran 2.0.0, which also produced the same problem in this server).

Django development server on LAN

It's my first time creating a django project. Now I'm at the point where I need to run the development server in the LAN. Except I can't get it to work.
My computer is connected with ethernet and the other computers in the network are connected via Wifi don''t know if that's relevant though.
What I tried by running the following:
The ip adress I found using ifconfig and copying inet addr: under ens33.
- python manage.py runserver myipadrres:8000
- python manage,py runserver 0.0.0.0:8000
The 0.0.0.0 doesn't even work on the windows os on my own computer. The ipadress does work for that.
Django settings debug is set to True.
Like I said it's the first time creating such a project and I don't know much about web related stuff. So I might have forgot to install something that I don''t know about.
Thanks in advance for your help
EDIT:
Managed to get it working i just had to turn on bridged networking in my VM settings
Greetings,
Dani
If that setup is working on your localmachine then
Just use that localmachine Ip:port-number in your LAN pc as:
for example :
If local machine Ip = 192.168.6.25 and setup is running on 8000 port ,then open browser at LAN machine PC and use this:
192.168.6.25:8000
Even you can run the setup on different port by this command
./manage.py runserver 0.0.0.0:<your_port>

"Unable to bind localhost:8000" error while running sample application in google app engine

I have just installed GAE launcher and am trying to run a sample application to make sure it works and I am getting the below error.
raise BindError('Unable to bind %s:%s' % self.bind_addr)
google.appengine.tools.devappserver2.wsgi_server.BindError: Unable to bind localhost:8000
2014-03-24 10:54:54 (Process exited with code 1)
I am trying to run the python version of the app with python 2.7 and am using windows 8.1 operating system. I did not create any files for the app, I just created a new application and am trying to run it in localhost.
Can someone please tell me what this error means and how to fix it?
The app server starts two servers: one for your application, the other for development console.
Change the ip address for the development console with:
dev_appserver.py --admin_port=9000
Another process is already bound to port 8000. Use netstat -an or netstat -anb or similar to investigate. It may be another instance of your development server.
Edit: If port 8000 is really occupied, Command-line arguments in the The Python Development Server says you can append --admin_port to change the 8000 to another free port.
For me, I have to use both --admin-port and --port
dev_appserver.py --admin_port=9000 --port=9999 app.yaml
I hope it might help others using PyCharm to understand where to set the admin port to something different than 8000.
Go to your "Run/Debug configurations" and in the configuration tab, add the following into "additional options":
--admin_port=9000

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

How to make Django's devserver public ? Is it generally possible?

I'm currently trying out the Django framework and I would share/present/show some stuff I've made to my workmate/friends. I work in Ubuntu under Win7 via VMware. So my wish/desire is to send my current pub-IP with port (e.g http://123.123.123.123:8181/django-app/) to my friends so they could test it.
the Problem is - I use django's Dev server (python /path-to-django-app/manage.py runserver $IP:$PORT).
How do I make the devserver public?
EDIT:
Oh, there's something I forgot to mention. As I sad I use VMware with Ubuntu. I have a shellscript that returns me my current int-IP 192.168.xx.xx and saves it in a environment-variable ($CUR_IP)
So, each time I want to run django's devserver I simply execute
python /path-to-django-site/manage.py runserver $CUR_IP:8080
At this way I become an http-adress (e.g.http://192.168.40.145:8080/app-name/) which I CAN USE OUTSIDE my virtual machine. I could test it on my host (win7) machine. That's actually the reason why I asked the question. I thought there's a way to use the ext-IP and make runserver usable outside too
python manage.py runserver 0.0.0.0:8181
This will run development server that should listen on all IP's on port 8181.
Note that as of Jun 17, 2011 Django development server is threaded by default (ticket #1609).
From docs:
Note that the default IP address,
127.0.0.1, is not accessible from other machines on your network. To
make your development server viewable
to other machines on the network, use
its own IP address (e.g. 192.168.2.1)
or 0.0.0.0.
Assuming you have ruby installed, you just have to get localtunnel:
gem install localtunnel
then start your python development server with:
python manage.py runserver 0.0.0.0:8000
in another shell, start localtunnel:
localtunnel -k ~/.ssh/id_rsa.pub 8000
That will output an url to access your local server.
Port 8000 is now publicly accessible from http://xxxx.localtunnel.com
That's it.
192.168.*.* is a LAN-private address -- once you've done the proper VMWare (or other VM manager) and firewall incantations to make it accessible from the LAN, it still won't be accessible from outside the LAN, i.e., from the internet at large (a good thing too, because such development servers are not designed for security and scalability).
To make some port of a machine with a LAN-private IP visible to the internet at large, you need a router with a "virtual servers" ability (many routers, even cheap ones, offer it, but it's impossible to be specific about enabling it since each brand has its own idiosyncratic way). I would also recommend dyndns or other similar service to associate a stable DNS name to your always-varying public IP (unless you're splurging for a static IP from your connectivity provider, of course, but the latter option is becoming costlier all the time).
superuser.com or serverfault.com may provide better answers and details (once you give every single little detail of your configuration in a question) since the question has nothing much to do with software development and everything to do with server administration and configuration.
I had to add this line to settings.py in order to make it work (otherwise it shows an error when accessed from another computer)
ALLOWED_HOSTS = ['*']
then ran the server with:
python manage.py runserver 0.0.0.0:9595
Also, make sure that your firewall allows communication to the chosen port (9595 in this case)
Already answered but adding npm alternate of same localtunnel
sudo npm install -g localtunnel
lt --port 8000 --subdomain yash
If you are using Virtualbox, You need to change the network setting in VB from "NAT" to "Bridged Adaptor". Then restart the linux. Now if you run sudo ifconfig you are able to see your IP address like 192.168.*.* . The last step is runserver
python manage.py runserver 192.168.*.*:8000
Cheers!
You need to configure bridged networking in VMWare and also grant access to the target port in Ubuntu firewall.
Alternatively, you can use cotunnel, Just run cotunnel in your ubuntu (in VMware) change your tunnel port in cotunnel dashboard which port you are using in local side. It gives public url and you can share the url with your friends.
Your Django server can listen to 127.0.0.1 or 0.0.0.0 (I prefer 0.0.0.0) it does not matter for cotunnel.
Might I suggest trying something like pyngrok to programmatically manage an ngrok tunnel for you? Full disclosure, I am the developer of it. Django example here, but it's as easy as installing pyngrok:
pip install pyngrok
and using it:
from pyngrok import ngrok
# <NgrokTunnel: "http://<public_sub>.ngrok.io" -> "http://localhost:8000">
http_url = ngrok.connect(8000)
No messing with ports or firewalls or IP addresses, and now you can also inspect the traffic (which is useful since what you're doing here is ongoing development, not running a prod-ready server).

Categories