I'm attempting to integrate social signon into a project, and am following along this tutorial: http://www.artandlogic.com/blog/2014/04/tutorial-adding-facebooktwittergoogle-authentication-to-a-django-application/.
Step #4 shows that the project requires a 'real url'. It appears you used to be able to specify a url when running manage.py runserver example.com (https://code.djangoproject.com/ticket/14928)
However, on Django 1.6.5 this results in CommandError: "example.com" is not a valid port number or address:port pair.
What is the easiest way to run a local webserver so that my django project appears at whateverurl.com?
If you are using a unix-like OS, edit /etc/hosts and include:
127.0.0.1 example.com
If you are on windows, look for %WINDIR%\system32\drivers\etc\hosts.
Then you can use python manage.py runserver example.com:80
Note that external servers will not be able to call example.com, if the API you are testing requires the provider server to call this URL directly, you can only use this to test against a local provider.
Related
I created an EC2 instance. Installed Python 3.4 on it and then installed Django 1.10.6 on it. I was trying to develop my first django application
I started django server.
python manage.py runserver
I could not access at http://n.n.n.n:8000.
I get a ERR_CONNECTION_REFUSED error.
I went back to the EC2 instance and added the protocol/port to the security group. This is how it looks after I add the port/proptocol
Custom TCP Rule TCP 8000 0.0.0.0/0
Custom TCP Rule TCP 8000 ::/0
It did not work. I even added a rule to allow all traffic from anywhere. It still did not work.
However, if I start django server the following way
python manage.py runserver 0.0.0.0:8000
I get the following error:
DisallowedHost at /
Invalid HTTP_HOST header: 'n.n.n.n:8000'. You may need to add 'n.n.n.n' to ALLOWED_HOSTS.
If tried adding the IP to ProjectName/settings.py,
ALLOWED_HOSTS = ['n.n.n.n'] #Make sure your host IP is a string
I get the ERR_CONNECTION_REFUSED error
I can ping the IP. I can ssh (there is rule to allow ssh). Does not look like there is a firewall.
$ sudo service iptables status
iptables: Firewall is not running.
Why am I not able access http/django server?
Thanks
Actually, I must not have started the server right, when I added the host to the ProjectName/settings.py file. I tried again, and this time it worked.
So looks like
django server started on EC2 instances with the following
python manage.py runserver
may not be accessible from other machines.
django server started with the following
python manage.py runserver 0.0.0.0:8000
would be accessible from the Internet provided the IP address of the host machine is added to the ALLOWED_HOSTS in the ProjectName/settings.py file
ALLOWED_HOSTS = ['n.n.n.n'] #Make sure your host IP is a string
This is all in addition to the entries in the security group
The IP to the allowed hosts means the IP of the devices which you want to access Django from.
I'm running a Django based server on a Mac. When running it using the default "python manage.py runserver" I can access it through a browser using "http://127.0.0.1:8000/".
The thing is I want to access it from other machines on the network. When I go to network settings I can see that the IP is for example 10.0.0.15. In the past I used to be able to run a Django based server using "python manage.py runserver 10.0.0.15:8000" and then access it using that address from any other machine in the local network, including the machine running the server.
Now, when I'm trying to access it using "http://10.0.0.15:8000/" even from a browser on the same machine I can see in the terminal that the server has received a request, but I get a Bad Request (400) response. What am I doing wrong?
I tried running python manage.py runserver 0.0.0.0:8000 as Leonardo Andrade suggested. It still didn't work, but it was the first part of the solution. The problem was that the DEBUG setting was False. In that case Django takes into account the ALLOWED_HOSTS setting.
Possible solutions:
Set DEBUG setting to True. This is a good idea for debugging anyway. ALLOWED_HOSTS setting is not taken into account in that case.
Keep DEBUG setting as False and add to ALLOWED_HOSTS '0.0.0.0' or '*' or your local ip (e.g. '10.0.0.15'). This is only for testing purposes. Make sure you don't allow just any hosts when you run a production server.
Of course, run the server on 0.0.0.0:8000.
A nice solution for accessing the server from other machines when the server runs an OS X is to go to Settings->Sharing on your Mac. There, under Computer Name you can see the name other computers can use to access this computer in a local network (e.g. my-mac.local). You can add that name to ALLOWED_HOSTS and then access the server using it (e.g. http://my-mac.local:8000/).
Try to run python manage.py runserver 0.0.0.0:8000
I'm working with PyCharm and I wonder if there's a way to make the Django embedded server accesible for the other hosts in my local network or I need to deploy my app on a dedicated web server such as Apache?
Now, I'm accessing my Django app like this in the browser:
http://localhost:8000/mypage/
and I want other users inside my local network to type:
http://my_private_ip:8000/mypage/
in their browsers and see the same page.
Just run the server (which is Django's embedded server FWIW, not PyCharm's) under http://my_private_ip:8000:
# ./manage.py help runserver
Usage: manage.py runserver [options] [optional port number, or ipaddr:port]
Starts a lightweight Web server for development.
(...)
# ./manage.py runserver my_private_ip:8000
Assuming a Unix environment.
You need to ensure the server is listening not on the lo interface but on all interfaces (or at least the one used to connect to the LAN).
If you can customize the way PyCharm launches the server, use 0.0.0.0 as the host, as in:
python manage.py runserver 0.0.0.0:8000
Your coworkers can then use your LAN IP address. If you don't know it, use $ ip a.
So, I have looked around stack overflow + other sites, but havent been able to solve this problem: hence posting this question!
I have recently started learning django... and am now trying to run it on ec2.
I have an ec2 instance of this format: ec2-xx-xxx-xx-xxx.us-west-2.compute.amazonaws.com on which I have a django app running. I changed the security group of this instance to allow http port 80 connections.
I did try to run it the django app the following ways: python manage.py runserver 0.0.0.0:8000 and python manage.py runserver ec2-xx-xxx-xx-xxx.us-west-2.compute.amazonaws.com:8000 and that doesnt seem to be helping either!
To make sure that there is nothing faulty from django's side, I opened another terminal window and ssh'ed into the instance and did a curl GET request to localhost:8000/admin which went through successfully.
Where am I going wrong? Will appreciate any help!
You are running the app on port 8000, when that port isn't open on the instance (you only opened port 80).
So either close port 80 and open port 8000 from the security group, or run your app on port 80.
Running any application on a port that is less than 1024 requires root privileges; so if you try to do python manage.py runserver 0.0.0.0:80 as a normal user, you'll get an error.
Instead of doing sudo python manage.py runserver 0.0.0.0:80, you have a few options:
Run a pre-configured AMI image for django (like this one from bitnami).
Configure a front end server to listen on port 80, and then proxy requests to your django application. The common stack here is nginx + gunicorn + supervisor, and this blog post explains how to set that up (along with a virtual environment which is always a good habit to get into).
Make sure to include your IPv4 Public IP address in the ALLOWED_HOSTS section in Django project/app/settings.py script...
So for a school project, I have to follow the steps in the "Writing your first Django App" Tutorial on Django's website, but we're supposed to have it on our EC2 instances, which are running Ubuntu 12.04.
In the tutorial, it says:
Now, open a Web browser and go to “/admin/” on your local domain – e.g., http://127.0.0.1:8000/admin/. You should see the admin’s login screen:
That must mean I have to access the EC2's local domain on my computer, right? How should I go about doing this?
I've tried (with my correct address in the x's) "ec2-xx-xxx-xx-xx.us-west-2.compute.amazonaws.com/home/admin/", "ec2-xx-xxx-xx-xx.us-west-2.compute.amazonaws.com/admin/", and even using the user's directory I'm using "ec2-xx-xxx-xx-xx.us-west-2.compute.amazonaws.com/user/admin/".
I put the project in the user's folder, so it's in /home/user/my_django_project/
I've accessed and used EC2 successfully before by putting PHP and HTML projects in the /home/user/public_html/ folder, but I have no clue what to do for this.
Run the following command in the Django application folder:
python manage.py runserver 0.0.0.0:8000
Add a rule to your Security Group to allow Inbound TCP through port 8000. You can use a Custom TCP Rule to specify that only port 8000 be allowed in.
Open your browser and go to the following link:
http://<EC2_ADDRESS>.amazonaws.com:8000/admin/
The admin page should now load and you should be able to see the GET requests from your local computer on your Amazon server. e.g [29/Mar/2015 03:35:24] "GET /admin HTTP".
I guess you run Django via the manage.py runserver command? If so Django is currently only listening on 127.0.0.1. Start django using
manage.py runserver 0.0.0.0
in order for it to listen on all IPs. You should then, if configured properly, be able to reach it via "ec2-xx-xxx-xx-xx.us-west-2.compute.amazonaws.com:8000/admin/".