Skip to content

Django Local Network Access

Amin Zamani edited this page Jul 14, 2024 · 3 revisions

There are two main ways to access your Django site on localhost from your mobile device:

1. Local Network Access:

This method works if your mobile device and your computer are connected to the same Wi-Fi network.

Here's what you need to do:

  • Find your computer's IP address:

    • On Windows: Open Command Prompt and type ipconfig. Look for the IPv4 address.
    • On Mac: Open System Preferences > Network. Select your Wi-Fi connection and look for the IP Address.
  • Update Django settings:

    • Open your project's settings.py file.

    • Find the ALLOWED_HOSTS setting. This is a list of allowed hostnames or IP addresses that can access your site.

    • Add your computer's IP address you found earlier within quotation marks to the list. For example:

      ALLOWED_HOSTS = ["192.168.1.100", "localhost"]  # Replace with your actual IP

      or

      ALLOWED_HOSTS = ["*"]  
  • Start the Django development server with 0.0.0.0:

    • In your terminal, run the command:

      python manage.py runserver 0.0.0.0:8070
    • This tells the server to listen on all network interfaces (0.0.0.0) instead of just localhost (127.0.0.1).

  • Open the site on your mobile:

    • Open your phone's web browser and enter the IP address of your computer followed by the port number (e.g., http://192.168.1.100:8070).

2. Development Server with Internal Network Exposure (Not recommended for production):

This method exposes your development server to the internet, allowing access from any device connected. This is not recommended for production due to security concerns.

Here's how (use with caution):

  • Install django-extensions:
pip install django-extensions
  • Run the server with runserver_insecure:
python manage.py runserver_insecure 0.0.0.0:8070
  • This command from django-extensions exposes the server publicly.

  • Open the site on your mobile:

  • From any device connected to the internet, enter your public IP address followed by the port number in your mobile browser (e.g., You can find your public IP address by searching "what is my ip" on Google).

Important Note: Exposing your development server to the internet is not secure for production environments. Always deploy your Django site to a proper web hosting service for public access.

Python

Python Essentials 1 (PCEP)

Introduction to Python and computer programming

Data types, variables, basic I/O operations, and basic operators

Boolean values, conditional execution, loops, lists and list processing, logical and bitwise operations

Clean Code

Algorithms

Django

Django Rest Framework

API

pip

SQLAlchemy

FastAPI

Pytest

TDD

Git

Linux

Docker

Python Testing

Interview Questions

Clone this wiki locally