First App: devel server - can't establish a connection to 127.0.0.1

330 views
Skip to first unread message

Rob

unread,
Aug 23, 2008, 8:23:44 PM8/23/08
to Django users
Running Fedora and Python 2.4. Working my way through the first
installation... I've successfully run "python manage.py runserver" and
gotten the expected

Validating models...
0 errors found
Django version 1.0-beta_1-SVN-unknown, using settings 'dja.settings'
Development server is running at http://127.0.0.1:8000/

response. Hoo-ray!

Next, in "Writing your first app..." it says, "Now that the server’s
running, visit http://127.0.0.1:8000/ with your Web browser. You’ll
see a “Welcome to Django” page, in pleasant, light-blue pastel. It
worked!"

Not for me! :( I get a "Unable able to connect. Firefox cannot
establish a connection to the server at 127.0.0.1:8000" message. I've
searched the group messages and there are only a handful of
(unrelated) messages about this.

I've checked my /etc/hosts to make sure that 127.0.0.1 is defined
(initially, it wasn't, only ::1.) I can navigate to http://127.0.0.1
and get a dummy index.html page I've set up. Since the manage.py
runserver command worked, it would seem that the development server is
running. But no joy in the browser.

If it's any help, I'd actually rather be running Apache +
mod_python... you know, make your development and production
environments as similar as possible...

Any ideas?

r.

Jeff Anderson

unread,
Aug 23, 2008, 9:13:56 PM8/23/08
to django...@googlegroups.com
Rob wrote:
> Not for me! :( I get a "Unable able to connect. Firefox cannot
> establish a connection to the server at 127.0.0.1:8000" message. I've
> searched the group messages and there are only a handful of
> (unrelated) messages about this.
>
First question: are you really running the development server on your
local box? If you're sshing to another machine, then it won't work.
127.0.0.1 is always the machine it is referenced from. You can change
where the development server is being run by locating your ip address
(use the ifconfig command and look for the address associated with
eth0), and running the dev server like this:

python manage.py runserver <ipaddress>:8000

In a common case, it might be:

python manage.py runserver 192.168.1.3:8000

You can then connect to it via that ip address instead, so if you are
SSHing to another machine, you can access the dev server even though
it's over the network. Just keep in mind that it'll be accessible to
anyone who can see that machine.

Your /etc/hosts don't define ip addresses, they define hostnames-- it
seems like you understood it backwards.


> If it's any help, I'd actually rather be running Apache +
> mod_python... you know, make your development and production
> environments as similar as possible...
>

This really isn't necessary when working with an initial Django project.
It's possible to use an apache instance with mod_python for development,
but it is nowhere near as convenient as the Django dev server. At least
for initial developing of Django projects, I'd recommend you stick with
the dev server-- it is there to help you be more productive and keep
things from getting in your way.

Hopefully this helps!


Jeff Anderson


signature.asc

Rob

unread,
Aug 23, 2008, 9:39:41 PM8/23/08
to Django users
> First question: are you really running the development server on your
> local box?

Yes, definitely the local box. Well, let me clarify... I've got Python
and Apache on the local box but my Apache Web root is actually on a
share on another box (my file server). But I just point to /home/rob/
path/to/file/server/sites and everything's good. I've built a number
of Web apps using other tools, such as PHP and Drupal without any
issues.

> If you're sshing to another machine, then it won't work.
> 127.0.0.1 is always the machine it is referenced from. You can change
> where the development server is being run by locating your ip address
> (use the ifconfig command and look for the address associated with
> eth0), and running the dev server like this:

eth0 Link encap:Ethernet HWaddr 00:1C:25:10:A9:6B
inet addr:192.168.1.115 Bcast:192.168.1.255 Mask:
255.255.255.0
inet6 addr: fe80::21c:25ff:fe10:a96b/64 Scope:Link

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host

Navigating to http://192.168.1.115:8000 fails with the same message.
So I don't think the local box vs remote box is the issue.

> Your /etc/hosts don't define ip addresses, they define hostnames-- it
> seems like you understood it backwards.

Ack. I think I knew that. Evidently not well enough. :)

So... still stuck.

r.

Erik Allik

unread,
Aug 23, 2008, 10:00:14 PM8/23/08
to django...@googlegroups.com
"python manage.py runserver 0.0.0.0:8000" is always easier than
looking up the IP address using ifconfig -- It simply listens on all
IP addresses. :)

Erik

Rob Erbaron

unread,
Aug 23, 2008, 10:42:24 PM8/23/08
to Django users
SOLVED. (and a followup question)

I was running "python manage.py runserver" in a terminal, and then hit
Ctrl-C... and then called up my Web browser.

So, duh, I was shutting down the server in the terminal window and
THEN browsing....

Jeesh. /shakes head/

Leaving the terminal window open, running localhost:8000 displays the
blue "Congrats on your first Django page" page.

Next question: Is there a way to set up this development server as a
service so I don't have to start it from a terminal each time?

r.

Karen Tracey

unread,
Aug 24, 2008, 12:28:11 AM8/24/08
to django...@googlegroups.com
On Sat, Aug 23, 2008 at 10:42 PM, Rob Erbaron <robert....@gmail.com> wrote:

Next question: Is there a way to set up this development server as a
service so I don't have to start it from a terminal each time?

Each time what?  It's a development server, expected to be used as you develop your code.  It's pretty good but not perfect about re-loading itself as you make changes so you can generally leave it running in a terminal window as you change code and it will usually automatically pick up changes.  Sometimes if you make a catastrophic coding error it will fail to reload and then you'll need to manually restart it.  It outputs information about the requests it processes (and any debugging print statements you put in your own code) so its terminal window is a useful debug tool.  It's no doubt possible to set it up as an auto-started service but I really don't know why you'd want to run it that way.

Karen

Robert Erbaron

unread,
Aug 24, 2008, 10:09:07 AM8/24/08
to django...@googlegroups.com
> Each time what? It's a development server, expected to be used as you
> develop your code. It's pretty good but not perfect about re-loading itself

I typically do a long-term development session for a day or two...
then go off an do another project for a while (a couple days.) So I'd
shut everything down.

At this advanced age, I'll likely forget to start the dev server up
again when I begin another dev session, and then post a dozen messages
pretty much like the one that started this thread. :) I would guess
I'd get the hang of it by, oh, December.

It's also just 'icky' having a terminal window open, just hanging
here. 'spose I can just move it to another panel, huh?

Maybe when I finish the Dj book I'll be able to complete my
Apache/mod_python config. (I started it last night... bad idea,
configuring something new late Sat night.)

Thx all!

Reply all
Reply to author
Forward
0 new messages