why is django server not working? (connection refused error) - python

I am doing a course : cs50 web programming with python and in project 2 Commerce while using
python manage.py runserver I am getting this error:
This site can’t be reached
127.0.0.1 refused to connect.
this is project 2 commerce. https://cs50.harvard.edu/web/2020/projects/2/commerce/
I have not made any changes to the distribution code
for my last project I was able to make it work by using this code in settings.py :
ALLOWED_HOSTS = ["ide-2f9427eaa96d41debb489eacf31c97d6-8080.cs50.ws"]
and changing url to the same
but on using it in this project I get this error:
403 Forbidden
edit
this is the solution I found from the comments:
As suggested in the comments I changed ALLOWED_HOSTS = [*] in settings.py of my django file.
then in the terminal I tried running the command python manage.py runserver 0.0.0.0:8080
On clicking the link I got a URL like this:
{ide URL}:8080
and this error:
This site can’t be reached
next I changed the URL manually to {IDE URL}-8080.cs50.wswhich is the URL for the web server in the IDE I am using.
this seemed to work for me.
The problem may have been because port 8000 is being used by another service and earlier I was not able to use port 8080 because I was using the wrong URL for my IDE's web server.

check settings.py and make sure debug is set to True. Then go to allowed hosts and set it to ['*'].
This will allow anyone on your system to connect to localhost server

By default the server runs on port 8000 so you might want to try 127.0.0.1:8000 in your URL

Related

Django refuses to connect

I created my Django website, whenever I try to go on the website, it says 127.0.0.1 is not responding. I tried troubleshooting it and it says 127.0.0.1 is refusing connection. everywhere it says that there's a firewall issue how do I fix
Just to be sure because you didn't mention it, did you launch the server with the following command?
python manage.py runserver
use this command in cmd:
python manage.py runserver
after that, you will see the IP and the port as shown in the image below
http://127.0.0.1:8000

Virtualhost on SSL - Can't run Django app in virtualenv after upgrading from httpd 2.2 to 2.4

I need help in understanding if I have correctly upgraded my website's older config from httpd-2.2 to httpd-2.4. It was hosted on a local server that we have since retired and the entire /etc/httpd and /var/www directories were copied to an EC2 instance with MySQL installed on the instance itself.
The Django-1.5 app (yes it needs to be upgraded) runs on the mod_wsgi module in daemon mode. I have upgraded the Apache modules and now when I run python manage.py runserver after activating my virtualenv environment and it gives no errors. But when I navigate to my EC2 public IP address with https, it keeps loading the page and times out afterwards. At the moment the httpd.conf redirects any port 80 requests to the website domain address, but I'd like to test the deployment on EC2 using bare IP address first before we can update our DNS records.
Another thing I did was to add the public IP address of my EC2 machine to the ALLOWED_HOSTS list, along with both localhost and 127.0.0.1.
Possible SELINUX problem tried but didn't work
The output of running httpd after runserver gave the following output:
(13)Permission denied: AH00072: make_sock: could not bind to address [::]:80
(13)Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs
I tried selinux in both permissive and non-permissive modes and nothing changed.
Please check my config files below and let me know if something doesn't seem right for httpd-2.4:
EDIT Apache runs fine. I have put an example HTML file in /var/www/html and it rendered when I went to the home page on my IP address. It is the Django app that doesn't seem to run, even when I do python manage.py runserver
/etc/conf/httpd.conf pastebin link
/etc/conf.d/vhosts.conf pastebin link
/etc/conf.d/ssl.conf pastebin link
Django settings.py pastebin link
Django default config file pastebin link
manage.py pastebin link
wsgi.py pastebin link

Error 404 when trying to access a Django app installed in a subdomain

I just installed Django and create a project and an app following the basic tutorial part 1, I created a virtualenv since centOS default python version is 2.4.3, I also created a subdomain to work on this for the development phase. when I try to access like dev.domain.com/admin/ or dev.domain.com/ I get a 404 error, it's like django is not even there. When I run the server I get a normal response:
(python2.7env)-bash-3.2# python manage.py runserver
Validating models...
0 errors found
February 22, 2014 - 23:54:07
Django version 1.6.2, using settings 'ct_project.settings'
Starting development server at http://127.0.0.1:8000/
Any ideas what I'm missing?
EDIT:after starting the server correctly(with the right ip) I tried again and as a result I got the browser hanging. Then I went to tried an online port scanner and found out that the port 8000 is not responding, any ideas what I can try next?
Thanks
You need to have you hosts entry on /etc/hosts like the following one
127.0.0.1 dev.domain.org
By default Django start the dev web server on port 8000 and you browser is looking for the server on port 80 (default port for webservers) so you need to add the port at the end of the url
http://dev.domain.com:8000.
if you want to start the server in default port 80 you need to specify it (migth need root or sudo):
python manage.py runserver http://dev.domain.com:80
The issue was solved by contacting the support service and asking them to open the port 8000 for me.

django-social-auth : How to redirect example.com to 127.0.0.1:8000?

I am sure many Django developers must come across this issue when using the social-auth.
Initially when you develop it, you would like to test it on your local server, hence you would redirect the domainname in your etc/hosts.
I came along this in the documentation:
https://github.com/omab/django-social-auth#facebook
If you define a redirect URL in Facebook setup page, be sure to not
define http://localhost:8000 because it won't
work when testing. Instead I define http://myapp.com and setup a
mapping on /etc/hosts or use dnsmasq.
From my understanding you can not define any ports in /etc/hosts.
Hence defining this entry there:
127.0.0.1 example.com
still doesn't hit my Django server that runs at 127.0.0.1:8000.
How do you guys do this?
Thanks,
Everyone says, "add example.com to your hosts file..." but neglects to mention that you should use example.com:8000 after starting the runserver. Here are more detailed steps that worked for me:
On linux:
open a terminal
sudo gedit (or replace gedit with the text editor of choice)
Open the etc/hosts file
add a line: 127.0.0.1 example.com (if you already have a line starting with 127.0.0.1 you can leave it - https://serverfault.com/questions/231844/is-it-safe-to-add-additional-127-0-0-1-entries-to-etc-hosts)
save the file
start your django dev server - python manage.py runserver
open a browser and go to example.com:8000 (this gives the correct callback to google and other sites that will not work with 127.0.0.1 or localhost)
You should see the home page of your django site.
Go to the social site you want to connect with and set up your client ID, using example.com as the website name. For example, the callback url for google is http://example.com:8000/complete/google-oauth2/
Copy the appropriate key/id settings and paste into your SETTINGS.py
Now your dev server should work!
I know this is an older post, but I could not find the complete steps anywhere. Please add clarifications if necessary as I am not an expert with this.
I have solved the redirection problem by following the steps here: https://serverfault.com/questions/397364/how-to-setup-named-virtual-hosts-in-nginx
In short, you need an entry in /etc/hosts as I have above plus nginx proxy between.
Install fiddler. Once installed, go to tools > Hosts.
Then you can map from 127.0.0.1:8000 to mysite.com
The following finally fixed it for me...
Under Authorized JavaScript origins: http://localhost:8000
Under Authorized redirect URIs: http://localhost:8000/page-name-here
If any of you guys is still struggling after adding 127.0.0.1 mysite.com to /etc/hosts, check whether you're using a VPN. I was still getting the error, "Unable to connect to mysite.com:8000". I resolved this error by turning off my VPN.

Python 2.6.2, Django 1.0.3, Windows XP, Page not found: /

I'm just starting to learn Python and Django and an unable to get the most basic app working. I've setup Python, added python to the Path environment variable, installed Django using install.py script.
I created an app by running the command
django-admin.py startproject my_project
updated the settings.py file for a database
DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = 'mysitedb'
Ran the command
python manage.py syncdb
And finally, started everything up
python manage.py runserver
To this point, everything looks to have run successfully. When I got to view http://localhost:8000/ I get the error "Page not found: /"
I originally installed Django version 1.1, but got the same error, so I removed it and tried the older version 1.0.3. Niether work. Any help would be appreciated.
To complete this question - #artran's answer of changing the port
python manage.py runserver 8001
will work.
When python runs the server, it automatically uses port 8000 (hence http://127.0.0.1:8000/). It uses this port as to not tread on the toes of other applications using localhost ports. However, you may still have an application or service running through this port. As such using port 8001 or any other port you may consider free should work.
To repair this in the future, you need to run a program of which can finger all your ports and determine what application is using the :8000 port.
It sounds like you need to create some apps for your project and set up the urls. As you are just starting you'd be best following the tutorial right through to get a feel for it all.
You probably have ADMIN_MEDIA_PREFIX = "" in your settings. Django intercepts requests to this url and attempts to serve admin media, thus when you make it an empty string, it will attempt to intercept ALL requests, resulting in nothing working.

Categories

Resources