During web application development, you may also want to check the in-progress design on mobile devices. Using a local IP address, you can browse the app you are developing. Here are the key steps on how to do it.
There are several ways to check your local IP address.
First, you can check it from the command line. Run the ifconfig
command (ipconfig
command for Windows). As the command displays a lot of lines, you may need to search it with "192" by pressing Command + F. "192" is typically used for local IP addresses.
ifconfig
lo0: flags=xxx<up,loopback,running,multicast> mtu xxxx
:
inet 192.168.xx.xx netmask 0xffffff00 broadcast 192.168.xx.xx
:
You can also use the grep
command to get the answer directly, like shown below.
ifconfig | grep 192
inet 192.168.xx.xx netmask 0xffffff00 broadcast 192.168.xx.xx
You can also check the local IP address in System Preferences on Mac.
Open the settings.py file and edit the ALLOWED_HOSTS
section like shown below. The reason for also adding "localhost
" is that you may want to run the runserver
command using the localhost
address. If you don't add "localhost
" while adding another IP address, you cannot use the app using the localhost
address.
ALLOWED_HOSTS = ["localhost", "192.168.xx.xx"]
Go to the project directory in your terminal and execute the command like shown below.
python manage.py runserver 192.168.86.96:8000
Go to 192.xx.xx.xx:8000/employee-learning/course-list/ in your browser. 192.xxx is your local IP address. You can confirm that the website is accessible on your mobile device.
Note: Make sure your mobile device is connected to the same WiFi as your local computer running the Django application with the runserver
command.
Usually, the local IP address is a dynamic IP address defined by DHCP (Dynamic Host Configuration Protocol). Your computer's IP address will be updated regularly. When the IP address changes, you must redo the settings above. If you want to keep the same configuration, make the IP address static in the WiFi setting. However, you need to switch back to DHCP when using other WiFi networks, such as WiFi in a cafe. Otherwise, your laptop may not connect to the new WiFi network.
During web application development, you may also want to check the in-progress design on mobile devices. Using a local IP address, you can browse the app you are developing. Here are the key steps on how to do it.
There are several ways to check your local IP address.
First, you can check it from the command line. Run the ifconfig
command (ipconfig
command for Windows). As the command displays a lot of lines, you may need to search it with "192" by pressing Command + F. "192" is typically used for local IP addresses.
ifconfig
lo0: flags=xxx<up,loopback,running,multicast> mtu xxxx
:
inet 192.168.xx.xx netmask 0xffffff00 broadcast 192.168.xx.xx
:
You can also use the grep
command to get the answer directly, like shown below.
ifconfig | grep 192
inet 192.168.xx.xx netmask 0xffffff00 broadcast 192.168.xx.xx
You can also check the local IP address in System Preferences on Mac.
Open the settings.py file and edit the ALLOWED_HOSTS
section like shown below. The reason for also adding "localhost
" is that you may want to run the runserver
command using the localhost
address. If you don't add "localhost
" while adding another IP address, you cannot use the app using the localhost
address.
ALLOWED_HOSTS = ["localhost", "192.168.xx.xx"]
Go to the project directory in your terminal and execute the command like shown below.
python manage.py runserver 192.168.86.96:8000
Go to 192.xx.xx.xx:8000/employee-learning/course-list/ in your browser. 192.xxx is your local IP address. You can confirm that the website is accessible on your mobile device.
Note: Make sure your mobile device is connected to the same WiFi as your local computer running the Django application with the runserver
command.
Usually, the local IP address is a dynamic IP address defined by DHCP (Dynamic Host Configuration Protocol). Your computer's IP address will be updated regularly. When the IP address changes, you must redo the settings above. If you want to keep the same configuration, make the IP address static in the WiFi setting. However, you need to switch back to DHCP when using other WiFi networks, such as WiFi in a cafe. Otherwise, your laptop may not connect to the new WiFi network.