Open In App

How To Access Pc Django Server In Android

Last Updated : 22 Sep, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Django server is mostly run on computers but when you want to make your Django project responsive and do various testing. Then using mobile can be proved as an advantage. Here we will try to learn how we can deploy our website on our phones.

Stepwise Implementation

Step 1:

we have to first enable Python to communicate through a firewall. For that, you can search in the windows search bar for “allow an app through windows firewall“.

 

Step 2:

After that, you will see a list of applications that have two options to be clicked: 

  • Private, and
  • Public.

Scroll down and search for Python and python.exe and check them true for both public and private, This will allow your Django project to be accessed over the firewall, and the devices connected to the same wifi can access the things over the firewall.

 

Step 3:

Start a mobile hotspot and connect your pc with the same wifi as your phone.

Step 4:

After that connecting. Open your command prompt, and write ipconfig in it. You will see your IP details and also your ipv4 address. This way your phone can access your computer’s private network. 

 

Step 5:

After getting your IP address, go to the Django Project in settings.py, and add the IP address to your ALLOWED_HOSTS. This way your phone will not give DISALLOWED_HOST_ERROR, an Invalid HTTP_HOST header. 

 

Step 6:

After adding your ipv4 address to the allowed hosts, In the terminal write the command to start the server but with the extra argument of the host and the port.

Note: Port can be selected as you want.

Python3




python manage.py runserver 0.0.0.0:8000


 

This runs your server with the host 0.0.0.0, this host server can mean anything from accepting all IP addresses or blocking all the IP addresses to the default route. This tells all the IP addresses will be accepted to the default route.

Like 127.0.0.1 is a localhost server for the pc, allowing the device to send messages to itself. Same as 0.0.0.0 is an unspecified address that routes you to the default route or unknown target. It depends on the client and server on how it is seen.

Step 7:

Open your mobile phone and open your browser. Now type the IPv4 address of your pc with the port. You will see your site live.

Python3




192.168.43.28:8000
 
# write this in your phone by
# replacing your ip with 192.168.43.28:8000
# and then your webpage will be
# deployed in your phone.


Output:

 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads