Django development running on 127.0.0.1:8000 not accessible from same machine

12,095 views
Skip to first unread message

nav

unread,
Aug 27, 2012, 3:53:23 AM8/27/12
to django...@googlegroups.com
Dear Folks,

I am running my django development server on 127.0.0.1:8000 and accessing this address from my web browser on the same machine. In the past few days I have found thet the web browsers keep prepending the address with "www." when using the above address. 127.0.0.1 without the prot number works fine but the django development server requires a port number.

I have not encountered this problem before and am puzzled by what is happening. I am working on a Kubuntu 12.04 linux box and my /etc/hosts/ file is below if that helps:

====================
127.0.0.1       localhost
127.0.1.1       <mymachinename>

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
====================

TIA
Cheers,
nav

Anton Baklanov

unread,
Aug 27, 2012, 8:30:41 AM8/27/12
to django...@googlegroups.com
try running dev server with command like "./manage.py runserver 0.0.0.0:8000" - 0.0.0.0 means that socket will listen for connections on all interfaces.
other people in your network will be able to connect your box using your ip.

if this does not help - show us output of 'sudo iptables-save' and 'sudo ifconfig'


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/EZzlz6iQOGoJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



--
Regards,
Anton Baklanov

Anton Baklanov

unread,
Aug 27, 2012, 8:36:15 AM8/27/12
to django...@googlegroups.com
oh, i misunderstood your question.

try to type url with schema into browser's address bar. i mean, use 'http://localhost:8000/' instead of 'localhost:8000'. 
also it's possible that some browser extension does this, try disabling them all.

On Mon, Aug 27, 2012 at 10:53 AM, nav <navani...@gmail.com> wrote:

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/EZzlz6iQOGoJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



--
Regards,
Anton Baklanov

nav

unread,
Aug 28, 2012, 12:00:12 AM8/28/12
to Django users
Hi Anton,

Thank you for your email.

I have tried all of the methods you had suggested but to no avail.

In all my years of Django development the localhost address has worked
flawlessly. I have also tried with multiple Django projects and other
Linux installations and the problem persists. This makes me think this
is a DNS issue that may be due to a network related problem. In which
case I will have to investigate. I will post once I find a work around
or solution.

Cheers,
nav
> >https://groups.google.com/d/msg/django-users/-/EZzlz6iQOGoJ.> To post to this group, send email todjang...@googlegroups.com.

nav

unread,
Aug 28, 2012, 1:05:55 AM8/28/12
to django...@googlegroups.com
Found a workaround that works.

I assigned 127.0.0.1 in my /etc/hosts file to www.127.0.0.1 and everything works. From the research I have done I cannot prove conclusively if this is a problem on Ubuntu 12.04 machines or not because I could not find other people who were facing the same issue.

In addition I am not sure if assigning the above causes any security issues but since it is just a name I think it should be fine.

This issue may be related to not assigning a fully qualified domain name to the Linux host.

Thanks for your help Anton and hope this helps others.

Cheers,
nav
> >https://groups.google.com/d/msg/django-users/-/EZzlz6iQOGoJ.> To post to this group, send email todjango-users@googlegroups.com.
> > To unsubscribe from this group, send email to>django-users+unsubscribe@googlegroups.com.

jirka.v...@gmail.com

unread,
Aug 28, 2012, 1:09:20 AM8/28/12
to django...@googlegroups.com
Hi nav,

A long shot - do you happen to have a proxy defined in your browser? It is possible to define a proxy for *all* request (including localhost) - this would have the same effect.

HTH

Jirka
To post to this group, send email to django...@googlegroups.com.

Nandakumar Chandrasekhar

unread,
Aug 28, 2012, 1:25:50 AM8/28/12
to django...@googlegroups.com
Hi Jirka,

That does not seem to be the case. I set rhe proxy server settings to no
proxy and it still prepends a www in front of the IP address. I could
investigate this further but I am little pressed for time at present.

Thanks,
nav

Chris Lawlor

unread,
Aug 31, 2012, 11:57:02 AM8/31/12
to django...@googlegroups.com
Jirka,

Is your app possibly doing a 301 (Permanent) redirect to www.* ? Or possibly some other app you were working on recently? Browsers will cache 301 redirects and automatically do the redirect WITHOUT making the initial request to 127.0.0.1, so if some project you were working on issued that redirect at any point, it will keep doing it, even if your current project doesn't issue a redirect. Try clearing your browser's cache.

Chris

Chris Lawlor

unread,
Aug 31, 2012, 11:57:53 AM8/31/12
to django...@googlegroups.com
Oops that should have been addressed to nav, sorry

Nandakumar Chandrasekhar

unread,
Aug 31, 2012, 12:52:04 PM8/31/12
to django...@googlegroups.com
Chris,

Thank you for your email. I had cleared my cache quite a number of times
before.

What is interesting is that if I start a new Django 1.4.1 the browser
finds the server running at 127.0.0.1:8000 and says it worked.

The application I am working on however still redirects to
www.127.0.0.1:8000 and yes it does do a 301 redirect. The application is
running on Django 1.2.5 but I doubt the version is at fault. I will need
to investigate further.

Cheers,
nav
> <http://127.0.0.1:8000> and accessing
> <https://groups.google.com/d/msg/django-users/-/EZzlz6iQOGoJ>.>
> To post to this group, send email todjang...@googlegroups.com.
> >>> To unsubscribe from this group, send email
> to>django-users...@googlegroups.com.
> >>> For more options, visit this group at
> >>> http://groups.google.com/group/django-users?hl=en
> <http://groups.google.com/group/django-users?hl=en>.
> >>
> >> --
> >> Regards,
> >> Anton Baklanov
> >
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/J-wSSpx9UcQJ.
> To post to this group, send email to django...@googlegroups.com.

nav

unread,
Sep 1, 2012, 3:31:54 AM9/1/12
to django...@googlegroups.com
Dear All,

hank you for all your replies the reason why a localhost was prepending a www in front was because of the PREPEND_WWW=True setting which was not present before. Once this setting is commented out everything works as it should.

Hope this saves someone some time in the future.

Thanks,
nav
> django-users+unsubscribe@googlegroups.com.

Melvyn Sopacua

unread,
Sep 2, 2012, 1:35:09 AM9/2/12
to django...@googlegroups.com
On 1-9-2012 9:31, nav wrote:

> hank you for all your replies the reason why a localhost was prepending a
> www in front was because of the PREPEND_WWW=True setting which was not
> present before. Once this setting is commented out everything works as it
> should.
First of all, thanks for following up and not leaving the search results
without an answer.

> Hope this saves someone some time in the future.
It can save someone more time if you'd file a bug report for it. Django
should make no attempts to prepend www if the requested hostname is a
raw IP address (for both IPv4 and 6). It makes no sense to do that.


--
Melvyn Sopacua

KamalKanta Majhi

unread,
Jan 16, 2015, 9:51:50 AM1/16/15
to django...@googlegroups.com
I h'v just run the django-admin.py runserver command to setup django dev server. But  dev server is not running at http://127.0.0.1:8000/. Also i h'v tested at http://0.0.0.0:8000/ and http://192.168.0.106:8000/. Throwing same error like below screen shot. Please help if anybody already resolved the same. 



-- Kamal

C. Kirby

unread,
Jan 16, 2015, 11:57:51 AM1/16/15
to django...@googlegroups.com
Try localhost:8000

KamalKanta Majhi

unread,
Jan 16, 2015, 1:02:19 PM1/16/15
to django...@googlegroups.com
Hi Kirby,

Thanks for the reply. The same Error is throwing at http://localhost:8000/ .


-- Kamal

James Schneider

unread,
Jan 16, 2015, 2:52:35 PM1/16/15
to django...@googlegroups.com

You should be running 'python manage.py runserver' from inside the directory of your project root , not using the django-admin.py command. The manage.py file should have been automatically generated when you created the project using django-admin.py. I hadn't even realized that django-admin.py supported the 'runserver' argument. It doesn't work for me, but 'python manage.py runserver' runs fine (and is what is recommended in the tutorial). 

It should look something like this:

$ cd <project root> 
$ python manage.py runserver
Validating models...
0 errors found
January 16, 2015 - 04:17:18
Django version 1.6.6, using settings 'project_name.settings'
Starting development server at http://127.0.0.1:8000/ 
Quit the server with CONTROL-C.


The command should 'hang' without displaying any errors if it is running correctly. It stays open to accept HTTP requests to http://127.0.0.1:8000. As you make requests, they should show up under the command with the URL's that you are requesting and the response codes from the development server.

See the section here: https://docs.djangoproject.com/en/1.7/intro/tutorial01/#the-development-server

-James


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.

Aaron C. de Bruyn

unread,
Jan 16, 2015, 8:48:48 PM1/16/15
to django...@googlegroups.com
If it still doesn't work after doing what James suggested, you can look to see if python is actually 'listening' on port 8000.

From an 'elevated' command prompt (start->type 'cmd', right-click 'cmd' and hit 'run as administrator') type 'netstat -abno > netstat.txt' and hit enter.  Then type 'notepad netstat.txt' and you will see a list of all the ports and programs that are using them.

Use the 'find' feature in notepad to look for a program running on '8000'.  If you don't see Python, something is not working correctly.

Occasionally you might see another app that is using the port.  A few years back, Windows Small Business Server would occasionally seize random ports used by other applications for use for DNS queries.

-A


Reply all
Reply to author
Forward
0 new messages