Reputation: 143
I'm trying to change django project url, so that users, who wants to connect to website in local area network will see url instead of localhost:8000 or 127.0.0.1. I need to change localhost:8000/users/board to be http://example.eu. I've tried to python manage.py runserver http://example.eu
and then thought about changing url's but it doesn't work. Also tried to change hosts file(Windows OS), but as far as I understand I need real ip address not url. Is it possible to do this thing and how?
Upvotes: 4
Views: 10677
Reputation: 911
Run a local domain with the same port
sudo nano /etc/hosts
And for windows I believe you need to open:
C:\Windows\System32\Drivers\etc\hosts
....
127.0.0.1 localhost
127.0.0.1 vazkirtje.com
127.0.0.1 www.vazkirtje.com
.....
ALLOWED_HOSTS = ["localhost", "127.0.0.1", "vazkirtje.com", "www.vazkirtje.com"]
http://vazkirtje.com:8000
The solution is not perfect since you do have to specify the port you are using, but this does let you use a domain for your local Django application in a relatively easy manner;)
Run a local non-existent domain without specifying the port
If you do want to run it without specifying the port; so just vazkirtje.com then you can use port 80, because this is the default port for HTTP.
sudo python manage.py runserver 80
http://vazkirtje.com
Upvotes: 1
Reputation: 821
You can use python manage.py runserver 0.0.0.0:8000
. 0.0.0.0
means all IPv4 addresses on the local machine. So the server can be reachable by 127.0.0.1
and your private ip address like 10.10.5.8
. So now others can access the server using http://10.10.5.8:8000
. You the runserver on port 80
, so that port can be removed from the url (by default is 80).
But to use any domain instead of ip, you have to change the hosts file of all the clients using the server to add domain to ip address mapping. Alternatively you can configure local network server to map the particular url to your system ip.
Upvotes: 6