Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 2792  / 2 Years ago, mon, december 27, 2021, 3:22:42

I'm running the Django webserver locally, and I want be able to enter www.my-site.dev or username.my-site.dev and have that map to my Django application.



I've seen a lot of solutions for Apache, and have tried to add the following to my /etc/hosts file, assuming the Django server would also check /etc/hosts.



127.0.0.1:8000 www.my-site.dev  
127.0.0.1:8000 username.my-site.dev

More From » 12.04

 Answers
2

A few things



1) Django probably isn't referencing your hosts file. ( I say probably, because I don't use Django, but it doesn't make sense for it to reference the hosts file as it shouldn't need to do a lookup on itself).



2) The hosts is for local name resolution. It has nothing to do with ports. If you want those two sites to resolve to your local machine, you should have this in your hosts file.



127.0.0.1     www.my-site.dev    username.my-site.dev  


You can then access the site via your web browser by going to



www.my-site.dev:8000


The only way for you to not have to type in the 8000 is for you to make Django listen on port 80 (or providing you are doing SSL, 443). This should be configurable in Django, and shouldn't cause any issues (unless you are already running something that is using port 80).


[#32988] Tuesday, December 28, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rmiend

Total Points: 292
Total Questions: 101
Total Answers: 111

Location: Azerbaijan
Member since Tue, Aug 9, 2022
2 Years ago
;