How do I access my Django server from outside? - django

My computer is connected to our college's local network. I am able to access my django server in the same network from another computer. When I try to do the same from an outside internet connection, I get an " Webpage not found error" . I used the ip given by Whatsmyip.com to access it from outside. Also, I started the server using the command : python manage.py runserver 0:8000

Use something like:
LocalTunnel http://localtunnel.me/
Ngrok https://ngrok.com/
These create a tunnel to your localhost. You cannot host from a common IP shared by an internal network. Read more about localhost here: http://en.wikipedia.org/wiki/Localhost
Please note that the tools above allow you to share a link to your site and is mostly meant for development and testing. If you really want to host a Django server, either do it on an external server or contact your infrastructure team in college to see if they even allow such a thing.
For external hosting, Heroku (https://www.heroku.com) can be a good option with a reasonable free plan.

This depends on your college network. Often, computers in local networkds are behind a NAT (one single external ip for several clients). At this point, the request cannot be routed from out- to inside. Maybe a college technician can help you to route your page.

I think it's first important to note that manage.py runserver is for local development. It is not meant to be used for deployment.
If you want to access your website from "outside", you should consider deploying it. You can then read more about this here : https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
Also, like stated in other answers, depending on how is configured your college network, it may not be possible to access your development server from outside, because :
It probably has NAT rules for local networks
There are probably port restrictions and a firewall for outside access (usually college networks are very restrictive from inside AND from outside)

Related

Installer for local webapp for stock management using django

I am looking to build a webapp for stock management, since it does not need to be hosted on the internet( only admin and sellers can access it ), with it's database on the local computer, I need to find a way for making it easier for the sellers to use the webapp without running a server and all that stuff since they are not tech-savvy
A server is not mainly a computer on the internet or cloud. You can use a local computer as a server. This tutorial is a great way to gather all of the Django application's parts into a single docker-compose file. You can run this docker-compose on any computer, and every computer inside your local network would have access to it (obviously, you should put the computer running the docker-compose in your local network first). Make sure the server's firewall (The computer running the docker-compose) allows traffic on the application's port.

Can I still do port forwarding in order to make my local website public if I have two routers between me and the internet?

I am trying to host a website from my house. (It does not have to be very reliable and consistent, hence I'm hosting from my house from a Raspberry Pi).
My website is obviously working fine locally. I tried to configure port forwarding on my router. It did not work. I then realized that my IP address on https://www.whatismyip.com/ and my router IP address is not the same. After reading up I am suspecting that I am behind another router. That would make sense since I'm living in an estate/housing complex and one ISP provides internet to all units. I can't access the next router (probably due to security reasons from my ISP).
My question is, is there any way around this? Would an ISP in general perhaps grant me a port if I ask them?
P.s. I am using phpmyadmin with my website and I am using Java on a cron-job to execute a program every 2 minutes which changes the DB. So I am not sure website hosting on a third party site would be trivial in my case.
it works now. I emailed my ISP to ask about the situation. Without further questions they assigned me a public IP address. I configured port forwarding and it works. Seems like you only get a public IP if you ask for one.

How to ssh port forward into a server to access a mysql host server for local work on Django web app and Jupyter notebook?

I'm unfamiliar with this terrain, so if any one can guide me in a step by step manner- it would really help. My MySQL database sits on a AWS host X- "ec2-xxx-xxx-xxx-xx.compute-1.amazonaws.com". It is blocked to access from individual local machines and is usually accessed from another working server Y- "ec2-yy-yyy-yyy-yy.compute-1.amazonaws.com" through port '3306'. Now it is especially inconvenient to access this via terminal SSH every time and scripts while they run, its hard to prototype or build an elaborate app. I'd like to set up a SSH tunnel from my local to server Y to be able to access MySQL host X from my local machine, to run queries from my locally deployed Jupyter notebook as well as local working-in-progress Django web app.
The reason why I ask for something more step-by-step is that I have to port forward to another server hosting a redis database which again is accessible through a specific server only. So, I'll be able to carry the solution from here to there too. I'm willing to go into chat as well if needed, but I need to resolve this rather quickly. Thanks!
PS: I've tried many guides off of the internet, but nothing has worked, it's become clear to me that I'm missing some foundational understanding or pathway. That's why I'm here, trying to start from the ground.

How do I host my server from an external ip?

I run the command:
sudo python manage.py runserver 0.0.0.0:8800
But when I enter:
http://xx.xx.xxx.xxx:8800
Where the x's are my external ip. My iPhone can not access the site.
My friend did this before. How do I make this work?
A lot of things can be wrong with this. Open ports, firewalls and the list goes on and on. Regardless, the built-in django server is not suitable for production. It's intended for development and a load of one user.
Django says:
DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through security audits or performance tests. (And that’s how it’s gonna stay. We’re in the business of making Web frameworks, not Web servers, so improving this server to be able to handle a production environment is outside the scope of Django.)
See here for more details.
You probably have to enable port forwarding on your router, it blocks ports so that your external IP address is not vulnerable to attack. In order to do this go into your router's settings and forward the external port 8080 to the machine and port on your network that you are running your server on. You'll probably also want to make sure to reserve an internal IP address for that machine so that it won't change its IP each time you connect to the network, forcing you to change the settings and forward that port to whatever internal IP your machine gets.

Mac OS X web sharing and Django

I created a web app with Django and I have it running on localhost (http://127.0.0.1:8000/), my question is, how can I make it available to the world, using Mac OS X's web sharing or something?
Thanks!
While you start the server specify the public ip or for any ip use 0.0.0.0
Example:
sudo python manage.py runserver 0.0.0.0:80
If you start your application without ip and port its bind only for loopback which is 127.0.0.1 and will not accessible in your network.
First off, I would strongly suggest you not to serve a website from your Mac. It's a really bad idea™. Both Mac OS X web sharing and Django's included http server (which I assume you're using) are intended for testing purposes only, for a number of reasons concerning speed, security et al. which is frankly too long to post here (but I hope that someone will :)
Second, it's already open to the world: anyone can connect to your computer using your IP address instead of the loopback 127.0.0.1 (unless you're NATted). This, again, is quite useful to test it (and have your friends/colleagues/boss) test it temporarily, but again is not fit for production use. Really.
It depends what your real purpose is, what you mean by "available to the world...or something". If you do want it to be permanently accessible from the web, you need to host it on a server (be it shared or dedicated), you won't keep your Mac turned on forever, will you? :)
For hosting Django on shared hosting - I'd recommend webfaction, step-by-step tutorials on setting up Django project can be found in their screencasts and forums (9.50$ per month for basic plan, with two months money-back guarantee, which actually works, tried myself:). More options in Djangofriendly.com
For dedicated server, ask yourself if you favor managing whole server(OS, web server, database server, memcache, firewall, backups...)yourself. If the answer is "yes", check out Linode, Rackspace, or Slicehost or even amazon web services, but bear in mind it's more expensive, it's way more complicated, but that's what gives you the ultimated flexibility. Once you are ready to try - this is one of the best tutorials i've found in net for a given subject.
If all you need is a proof of concept, that "whatever i can access from my web browser, should be accessible from anywhere in the world", ask your ISP if you are given the private IPaddress. If not, hm, better go for options mentioned above :) If you do, then find out what IP it is by visiting whatismyipaddress.com. Then start the web server as Prashanth suggested, and enter the IP address from whatismyip.org in your browser. Get nothing? a)turn off firewall of MacOSx. still nothing? b)connect your Mac directly to ethernet cable your ISP provides, without router in between. Retry entering your ouside IP in the browser. Works? great, go google "Port forwarding ", this will tell you have to configure your router to have the same effect when router is being used. Doesn't? Ask separate question in stackoverflow and provide as much details about what you are doing as you can.
Mac os Web sharing is uselless if the packets aren't routed correctly to reach your computer on a network. I guess all it can do is start apache, and open some ports in a firewall. But if your personal router or ISP wont forward external packets to your computer - you won't get what you want.
Good luck!