How do I test my Django App on my Phone

3,551 views
Skip to first unread message

Muhammad Ali

unread,
Dec 9, 2013, 6:44:08 PM12/9/13
to django...@googlegroups.com
Hello,

I'm developing a Django-powered blog, with two versions: a desktop version and a mobile I optimized version for when it is accessed through a mobile device.

Now, I'm trying to test it on my Samsung phone to see how it would look and act like when someone uses it through a mobile phone's browser [iPhone, Android, etc.]

Instructions I found online (such as this one: ) say that I should plug the phone to the computer through a USB and run: manage.py runser 0.0.0.0:8000 and visit this IP address via my phone's browser. But it doesn't work and instead returns an error:

"Oops! Google Chrome could not connect to 0.0.0.0:8000"

What am I missing in the setup? What are other, if any, alternative ways of testing my Django app on my phone during development?

Thank you for your time and help.

Sincerely,
Muhammad

Nick Santos

unread,
Dec 9, 2013, 6:58:46 PM12/9/13
to django...@googlegroups.com
I'm not familiar with the method you mentioned - and don't think it should work unless you establish a network connection through your USB connection, amongst other things. In a basic sense, 0.0.0.0 is nonroutable if you try to access it externally. That runserver command, if I remember correctly, uses 0.0.0.0 to bind to all of your computer's IP addresses (so you can access it externally). A simpler way than trying to network over USB would be to connect your phone to the the same network (via wifi, unless that's not an option), and open port 8000 to your development machine in its firewall. Then determine that machine's public IP address (eg 1.2.3.4) and enter that into your browser as 1.2.3.4:8000. Then it should come up on your phone.
-Nick




--
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.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/47bac303-2b53-4f9d-bd93-acbc1d4f1b09%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Juan Pablo Romero Bernal

unread,
Dec 9, 2013, 6:59:15 PM12/9/13
to django...@googlegroups.com
Hi, 

Your phone must be connected to the same network that your workstation is connected. So, the django app must running listening on local IP address like 192.168.1.2:8000 and from phone you can access the application using this IP. 

Hope this helps, 



--
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.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/47bac303-2b53-4f9d-bd93-acbc1d4f1b09%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Juan 

Tim Chase

unread,
Dec 9, 2013, 7:08:15 PM12/9/13
to django...@googlegroups.com, mtec...@gmail.com
On 2013-12-09 10:44, Muhammad Ali wrote:
> Instructions I found online (such as this one: ) say that I should
> plug the phone to the computer through a USB and run: manage.py
> runser 0.0.0.0:8000 and visit this IP address via my phone's
> browser. But it doesn't work and instead returns an error:
>
> "Oops! Google Chrome could not connect to 0.0.0.0:8000"

The "runserver 0.0.0.0:8000" tells Django to listen on all interfaces
you have. You'd have to determine the IP address of your server
(well, dev machine). Usually you can get this from the output of
"ifconfig -a" (or "ipconfig /all" on Win32). It will usually return
something like 192.168.x.y

Depending on how you're tethered, you want to point your phone to
that address:

http://192.168.3.14:8000/

Some tethering forces the phone to appear outside your network,
preventing it from seeing the private/internal 192.168.x.y
addresses. This complicates matters, as you'd have to adjust your
router/NAT to open port 8000 (or port 80 for that matter) and point
it at your box internally. You'd then have to visit your site via
your external IP address. So you it might look something like

phone
|
v
internet
|
v
router 123.45.67.89
|
| configure router NAT to listen on 80
| and forward internally
| to 192.168.x.y on port 8000
v
computer 192.168.x.y listening on port 8000

You can find your external IP address by just googling for it:

https://www.google.com/search?q=my+IP+address

which includes the answer before the other actual search results.
Once you have that external address, you can use

http://123.45.67.89/

to access it (note that if you forward 8000-to-8000 instead of
80-to-8000, you'd have to specify the port as :8000 in the URL)

-tkc



Timothy W. Cook

unread,
Dec 9, 2013, 7:28:32 PM12/9/13
to django...@googlegroups.com, mtec...@gmail.com
Tim Chase's answer works well for a now and then test.  But many static IPs change every 24 hours or so.  Plus you will probably want to do this many more times in the future as well as ask others to test it on various devices. .  

I suggest setting up a  URL using  no-ip.org or similar service.  No-ip.org is free at this level and works great, at least on Ubuntu and CentOS.  I haven't tried other OS's.  

HTH,
Tim



--
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.
Visit this group at http://groups.google.com/group/django-users.




--
MLHIM VIP Signup: http://goo.gl/22B0U
============================================
Timothy Cook, MSc           +55 21 94711995
MLHIM http://www.mlhim.org
Like Us on FB: https://www.facebook.com/mlhim2
Circle us on G+: http://goo.gl/44EV5
Google Scholar: http://goo.gl/MMZ1o
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook

Tim Chase

unread,
Dec 9, 2013, 8:01:37 PM12/9/13
to django...@googlegroups.com
On 2013-12-09 17:28, Timothy W. Cook wrote:
> I suggest setting up a URL using no-ip.org or similar service.
> No-ip.org is free at this level and works great, at least on Ubuntu
> and CentOS. I haven't tried other OS's.

This Tim agrees with that Tim. :-)

It's one thing to go through finding your IP address once, then test
a bunch before the ISP changes it out from under you, and then be
done (or come back and do it again in a couple months). But if
you plan to do do it regularly over a long period of time, it is nice
to have an agent keep that information up-to-date for you with a
company like NoIP. It has the added benefit that I also route my
external port 22 to internal port 22, so I can ssh to my home machine
via an easily-remembered URL rather than by an IP address that can
change out from under me.

-tkc


Juan Pablo Romero Bernal

unread,
Dec 9, 2013, 8:03:17 PM12/9/13
to django...@googlegroups.com
Hi,  
I suggest setting up a  URL using  no-ip.org or similar service.  No-ip.org is free at this level and works great, at least on Ubuntu and CentOS.  I haven't tried other OS's.  

Or you can use localtunnel (http://progrium.com/localtunnel/) it's easy to install and works
fine on most *NIX. 

--
Juan 

mulianto

unread,
Dec 10, 2013, 5:15:53 PM12/10/13
to django...@googlegroups.com
Hi,

I guest your django app will be a web app run in a browser inside your phone.

For the easy way you can use your browser , in firefox open tools - web developer - responsive design view

You can test your django app in some phone mode with available screen resolution preset and also rotate it just like in a phone or tab.

No need from real phone because in android or ios the browser engine will have the same rendered output. 

Or the easy way is use wifi to make the phone and dev machine can talk and access it as usual  via browser.

Hope helps ˆ⌣ˆ 

Sent from my iPhone

Mulianto
--
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.
Visit this group at http://groups.google.com/group/django-users.

Muhammad Ali

unread,
Dec 14, 2013, 3:58:14 AM12/14/13
to Timothy W. Cook, django...@googlegroups.com

Hello,

I'm very sorry for the delay in letting you both know how it worked out for me.

I first tried Cook's method and signed up for the NO-IP service. But for some reason, I could not reach my local server from my phone's browser using the URL that I created there. (But I could access the URL from the computer and it showed the app I was working on.)

So, I kept looking for more solutions like it, especially since I want to be able to connect to my computer even when I am on a different network (library, cafe, etc.).

I came across LocalTunnel and ngrok (with which the former was being integrated and merged with). But it didn't work out for me. Maybe it's made for a different platform (I work on Windows.)

At this point,  using additional info I had gathered from the web, I went into my Firewall settings and setup a new rule to open up port 80 for TCP.

I then tried the NO-IP service again, but it didn't work.

Again, I kept looking...

And Portmap and PageKite came into view.

And, since PageKite.net's solution was a single Python script that I had to run on my computer and then try to access my local server from the URL that I set up (e.g. example.pagekite.me), I gave it a try.

I then executed "manage.py runserver 0.0.0.0:80" on the command line (in my Django project's directory)

It worked when I accessed the local server from both the web and my phone. "Ah," I thought, "the world is right again!" :)

Now, I am back to developing and testing both versions (mobile and web) of my site simultaneously.

Thank you both for the help and resources pointed out.  (And my apologies for the long silence.)

I wish you both all the best. :)

Sincerely,
Muhammad

vickster

unread,
Jul 29, 2014, 10:58:02 AM7/29/14
to django...@googlegroups.com

//On the terminal type the below line.

sudo python manage.py runserver 0.0.0.0:80

//type your password

//on your phone you only need to open the browser and on the search bar input the network's ip address (both devices should be connected to the same network)


Voila!

Reply all
Reply to author
Forward
0 new messages