Reputation: 97
I want to play around with social-django authentication app. Iwant to add for login with facebook. For that I need to change my 127.0.0.1 to something like my-site.com. I wanted to change /etc/hosts, unfortunetely it doesn't exist.
I created hosts file using touch command and added 127.0.0.1 my-site.com (nothing more) and restarted my computer. I tried runserver command and copy-pasted hostname above to the beggining of the link (my-site.com:8000) but it didn't work.
My django project runs on venv.
If you have any ideas on solving my problem, please share
(I've posted a similar question on superuser.com, but no one seemed to know a solution there, so I ask here)
EDIT my settings py now look like this
ALLOWED_HOSTS = ['my-site.com', '127.0.0.1']
But it still doesn't work
Upvotes: 7
Views: 21171
Reputation: 51
if you are on Mac or linux :
127.0.0.1 mysite.com
if you are on window:
127.0.0.1 mysite.com
Then flush DNS pushing system changes
sudo killall -HUP mDNSResponder
ipconfig /flushdns
Then add to settings.py
ALLOWED_HOSTS = [‘mysite.com’]
Finally, start your django application and you should be able to access it. Note that you must access with port whatever it is, the port nowadays should be 8000
Hence full path would be mysite.com:8000
Upvotes: 3
Reputation: 911
I posted a 7 step tutorial to achieve this with and without specifying the port, on a similar question for anyone still looking for a solution!
Upvotes: 0
Reputation: 348
Before everything, you need to add your localhost domain to ALLOWED_HOSTS variable in settings.py:
ALLOWED_HOSTS = ['my-site.com', '127.0.0.1', 'localhost']
If you use PyCharm as your IDE, you can edit your configuration settings as so:
Upvotes: 0
Reputation: 83
You can use localhost instead of 127.0.0.1 as one of the workaround.
Use this script:
$ python manage.py runserver localhost:8000
Upvotes: 7
Reputation: 46
You need to buy, or get for free, a DNS (you can get a subdomain from Noip for free). You then have to connect your domain to your router (search in the settings) and port forward your computer through the port you want. Now you will be able to visit "yourdomain.com" and you will get your django server. Don't forget to add your domain to ALLOWED_HOSTS. I wish it helps!
Upvotes: 0
Reputation: 306
You need to change the file settings.py so that my-site.com is contained in the list of ALLOWED_HOSTS.
For security reasons Django needs to know what server names it servers, which is specified by ALLOWED_HOSTS. On Django's web site it states that:
A list of strings representing the host/domain names that this Django site can serve. This is a security measure to prevent HTTP Host header attacks, which are possible even under many seemingly-safe web server configurations.
Django Settings: ALLOWED_HOSTS
Upvotes: 0
Reputation: 887
You can use LocalTunnel ,it allows you to easily share a web service on your local development machine without messing with DNS and firewall settings.
Install Localtunnel globally (requires NodeJS) to make it accessible anywhere:
npm install -g localtunnel
Run django server using
python manage.py runserver
and use the command line interface to request a tunnel to your local server:
lt --port 8000
It will give you a temporary url to use in any place,You can use that url in other sysytems too,the url will be live until the server is running in your system. You can also use the temporary url in facebook setting for testing purpose.
Upvotes: 0