-
Notifications
You must be signed in to change notification settings - Fork 4
Django Local Network Access
There are two main ways to access your Django site on localhost from your mobile device:
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.
- On Windows: Open Command Prompt and type
-
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
).
- Open your phone's web browser and enter the IP address of your computer followed by the port number (e.g.,
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.
- Introduction
- Variables
- Data Types
- Numbers
- Casting
- Strings
- Booleans
- Operators
- Lists
- Tuple
- Sets
- Dictionaries
- Conditionals
- Loops
- Functions
- Lambda
- Classes
- Inheritance
- Iterators
- Multi‐Processing
- Multi‐Threading
- I/O Operations
- How can I check all the installed Python versions on Windows?
- Hello, world!
- Python literals
- Arithmetic operators and the hierarchy of priorities
- Variables
- Comments
- The input() function and string operators
Boolean values, conditional execution, loops, lists and list processing, logical and bitwise operations
- Comparison operators and conditional execution
- Loops
- [Logic and bit operations in Python]
- [Lists]
- [Sorting simple lists]
- [List processing]
- [Multidimensional arrays]
- Introduction
- Sorting Algorithms
- Search Algorithms
- Pattern-matching Algorithm
- Graph Algorithms
- Machine Learning Algorithms
- Encryption Algorithms
- Compression Algorithms
- Start a New Django Project
- Migration
- Start Server
- Requirements
- Other Commands
- Project Config
- Create Data Model
- Admin Panel
- Routing
- Views (Function Based)
- Views (Class Based)
- Django Template
- Model Managers and Querysets
- Form
- User model
- Authentification
- Send Email
- Flash messages
- Seed
- Organize Logic
- Django's Business Logic Services and Managers
- TestCase
- ASGI and WSGI
- Celery Framework
- Redis and Django
- Django Local Network Access
- Introduction
- API development
- API architecture
- lifecycle of APIs
- API Designing
- Implementing APIs
- Defining the API specification
- API Testing Tools
- API documentation
- API version
- REST APIs
- REST API URI naming rules
- Automated vs. Manual Testing
- Unit Tests vs. Integration Tests
- Choosing a Test Runner
- Writing Your First Test
- Executing Your First Test
- Testing for Django
- More Advanced Testing Scenarios
- Automating the Execution of Your Tests
- End-to-end
- Scenario
- Python Syntax
- Python OOP
- Python Developer position
- Python backend developer
- Clean Code
- Data Structures
- Algorithms
- Database
- PostgreSQL
- Redis
- Celery
- RabbitMQ
- Unit testing
- Web API
- REST API
- API documentation
- Django
- Django Advance
- Django ORM
- Django Models
- Django Views
- Django Rest Framework
- Django Rest Framework serializers
- Django Rest Framework views
- Django Rest Framework viewsets