366👍
You have to run the development server such that it listens on the interface to your network.
E.g.
python manage.py runserver 0.0.0.0:8000
listens on every interface on port 8000.
It doesn’t matter whether you access the webserver with the IP or the hostname. I guess you are still in your own LAN.
If you really want to access the server from outside, you also have to configure your router to forward port e.g. 8000
to your server.
Check your firewall on your server whether incoming connections to the port in use are allowed!
Assuming you can access your Apache server from the outside successfully, you can also try this:
- Stop the Apache server, so that port
80
is free. - Start the development server with
sudo python manage.py runserver 0.0.0.0:80
38👍
I had to add this line to settings.py in order to make it work (otherwise it showed an error when accessed from another computer)
ALLOWED_HOSTS = ['*']
then ran the server with:
python manage.py runserver 0.0.0.0:9595
Also ensure that the firewall allows connections to that port
- [Django]-Do I need Nginx with Gunicorn if I am not serving any static content?
- [Django]-Dynamic choices field in Django Models
- [Django]-How to get username from Django Rest Framework JWT token
15👍
Pick one or more from:
- Your application isn’t successfully listening on the intended IP:PORT
- Because you haven’t configured it successfully
- Because the user doesn’t have permission to
- Your application is listening successfully on the intended IP:PORT, but clients can’t reach it because
- The server local iptables prevents it.
- A firewall prevents it.
So, you can check that your application is listening successfully by running lsof -i
as root on the machine and look for a python
entry with the corresponding port you’ve specified.
Non-root users generally cannot bind to ports < 1024.
You’ll need to look at iptables -nvL
to see if there’s a rule that would prevent access to the ip:port that you are trying to bind your application to.
If there is an upstream firewall and you don’t know much about it, you’ll need to talk to your network administrators.
- [Django]-Macros in django templates
- [Django]-Does SQLAlchemy have an equivalent of Django's get_or_create?
- [Django]-How to use subquery in django?
14👍
just do this:
python manage.py runserver 0:8000
by the above command you are actually binding it to the external IP address.
so now when you access your IP address with the port number, you will be able to access it in the browser without any problem.
just type in the following in the browser address bar:
<your ip address>:8000
eg:
192.168.1.130:8000
you may have to edit the settings.py
add the following in the settings.py in the last line:
ALLOWED_HOSTS = ['*']
hope this will help…
- [Django]-Django-way for building a "News Feed" / "Status update" / "Activity Stream"
- [Django]-Django models.py Circular Foreign Key
- [Django]-Django gunicorn sock file not created by wsgi
7👍
For AWS users.
I had to use the following steps to get there.
1) Ensure that pip and django are installed at the sudo level
- sudo apt-get install python-pip
- sudo pip install django
2) Ensure that security group in-bound rules includ http on port 80 for 0.0.0.0/0
- configured through AWS console
3) Add Public IP and DNS to ALLOWED_HOSTS
- ALLOWED_HOSTS is a list object that you can find in settings.py
- ALLOWED_HOSTS = [“75.254.65.19″,”ec2-54-528-27-21.compute-1.amazonaws.com”]
4) Launch development server with sudo on port 80
- sudo python manage.py runserver 0:80
Site now available at either of the following (no need for :80 as that is default for http):
- [Public DNS] i.e. ec2-54-528-27-21.compute-1.amazonaws.com
- [Public IP] i.e 75.254.65.19
- [Django]-How to get getting base_url in django template
- [Django]-How do I do an OR filter in a Django query?
- [Django]-Django model blank=False does not work?
5👍
open terminal
type : ifconfig
check results of ifconfig command
use the inet IP .. should look like this.. 192.168.1.121 or similar 192.168.x.x.
now runserver like you normally do but this time specify the inet IP
python3 manage.py runserver 192.168.x.x:8000 (replace the x with your inet)
also
on settings.py
ALLOWED_HOSTS = [‘*’]
- [Django]-Annotate with latest related object in Django
- [Django]-How to deal with "SubfieldBase has been deprecated. Use Field.from_db_value instead."
- [Django]-In a Django form, how do I make a field readonly (or disabled) so that it cannot be edited?
3👍
I’m going to add this here:
-
sudo python manage.py runserver 80
-
Go to your phone or computer and enter your computers internal IP (e.g
192.168.0.12
) into the browser.
At this point you should be connected to the Django server.
This should also work without sudo:
python manage.py runserver 0.0.0.0:8000
- [Django]-What are the limitations of Django's ORM?
- [Django]-Django error: got multiple values for keyword argument
- [Django]-Django-allauth social account connect to existing account on login
- [Django]-Github issues api 401, why? (django)
- [Django]-Jquery template tags conflict with Django template!
- [Django]-How can I avoid "Using selector: EpollSelector" log message in Django?
2👍
You need just to allow any hosts :
settings.py :
ALLOWED_HOST = ['*']
Run your server :
python3 manage.py runserver 0.0.0.0:8000
If you want to connect android app just add internet permission in AndroidManifest
It’s work for me 😉
- [Django]-How do I install psycopg2 for Python 3.x?
- [Django]-Django TextField and CharField is stripping spaces and blank lines
- [Django]-What is the purpose of adding to INSTALLED_APPS in Django?
1👍
install ngrok in terminal
sudo apt-get install -y ngrok-client
after that run:
ngrok http 8000
or
ngrok http example.com:9000
- [Django]-Django models.py Circular Foreign Key
- [Django]-Django: Grab a set of objects from ID list (and sort by timestamp)
- [Django]-Custom django admin templates not working
- [Django]-How to run celery as a daemon in production?
- [Django]-Celery : Execute task after a specific time gap
- [Django]-Django, Turbo Gears, Web2Py, which is better for what?