tags:

views:

136

answers:

3

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!

+1  A: 

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.

Agos
Why is OSX web sharing not good? - it is apache
Mark
the included http server from django is no good? what would be the replacement?
Johannes
Johannes, the Django **development** server is for development only and this is stressed time and time again in the *documentation*. See http://docs.djangoproject.com/en/dev/howto/deployment/#howto-deployment-index for production deployment methods
Ben James
Mark. OS X web sharing is an Apache controlled by Mac OS X to do one task which is not running Django applications. Using it is asking for trouble.
J. Pablo Fernández
It is not true that "it's already open to the world." If it's run with "127.0.0.1:8000", it's only available on the loopback interface. Django's dev server only binds to the interface you tell it to. If you want it to bind to all IP interfaces on the machine, you have to say "0:8000".
Carl Meyer
+4  A: 

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.

Prashanth
A: 

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!

toinbis