Django Server Error: port is already in use, docker [duplicate] - django

This question already has answers here:
Docker & Postgres: Failed to bind tcp 0.0.0.0:5432 address already in use
(11 answers)
Closed 9 months ago.
When working with Docker and Django setup Initially sometime we will getting this error port 5432 already in use or TCP/IP not able to make connection. How to resolve this issue please find below.

This issue will happen because of two cases :
By suddenly stop or restart the system without closing the docker or DB to resolve it kill all PID ID by running this command kill -9 PID and kill all PID
Second issue was happening due to already in our system another Docker is present with same configuration then we have to change its name. along with it dont forgot to Inssert this line into settings.py DOMAIN_URL = config("DOMAIN_URL", "http://localhost:8000/") or DOMAIN_URL = "http://localhost:8000/"

Related

Flask Webserver on Amazon Linux 2 - This site can’t be reached on browser [duplicate]

This question already has answers here:
Are a WSGI server and HTTP server required to serve a Flask app?
(3 answers)
Closed 17 days ago.
I have started a Flask Webserver on an Amazon Linux 2 EC2 instances
(venv) [ec2-user#ip-10-0-1-63 microblog]$ flask run
* Serving Flask app 'microblog.py'
* Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on http://127.0.0.1:5000
Press CTRL+C to quit
When i try to access the Web either via the below Public V4 DNS or Public V4 IP i get "Site cannot be reached"
http://34.228.161.61:5000
http://34.228.161.61:5000/index
https://ec2-34-228-161-61.compute-1.amazonaws.com:5000
https://ec2-34-228-161-61.compute-1.amazonaws.com:5000/index
I have successfully launched an Apache Web Server into the same EC2 & VPC instances and have no issues.
Also running curl from the same server i launched flask returns the contents
[ec2-user#ip-10-0-1-63 ~]$ curl http://localhost:7999
Hello, World![ec2-user#ip-10-0-1-63 ~]$
(tried a range of other ports also)
Any clues on what to do to get it working from my Chrome/Safari browser?
Tried so far
Ensured EC2 was talking to the web
Ensured VPC had route to the public internet
Ensured other webservers could be launched successfully from the same EC2 instance
Might be your application is not allowed for the outside world (0.0.0.0). Please check the running port in your system. You can use the below command to check:
sudo netstat -tulpn | grep LISTEN
check if 0.0.0.0: in your case, 0.0.0.0:5000 is showing in output or not.
Then try to run with below command:
flask run --host=0.0.0.0
Let me know, if that works. #Cloudkaramchari

Heroku deploy Django application [duplicate]

This question already has answers here:
Error R11 (Bad bind) -> Process bound to port 8000, should be 25162 (see environment variable PORT)
(1 answer)
Getting "Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch" on python
(2 answers)
Heroku: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch - Python
(1 answer)
Deploying python to Heroku - Web process failed to bind to $PORT
(1 answer)
Closed 6 months ago.
I'm trying to launch my Django application with Heroku but when I execute the command "Heroku local" I get the following error .... Anyone can explain why?
Before writing this post I tried to make various changes and read up on the official website but it didn't work.
To run heroku in local I ran
Heroku local
in my main directory, with gunicorn everything was fine but apparently with heroku I'm doing something wrong.
I've also created a Procfile with the following line inside of it:
web: gunicorn social_site.wsgi
where social_site is the name of the app.

Without server is it possible to run flask? [duplicate]

This question already has answers here:
Are a WSGI server and HTTP server required to serve a Flask app?
(3 answers)
Closed 12 months ago.
I have a flask application, and I want to run this application in production. Is it possible to do this without your own server and if yes where it is possible?
Yes, You can run the flask application through your own webserver such as Apache2 or Nginx hosted in your own server.
Check this out for more info
https://flask.palletsprojects.com/en/2.0.x/deploying/

How to share localhost port over local network [duplicate]

This question already has answers here:
Making django server accessible in LAN
(4 answers)
Closed 1 year ago.
I created webpage on local server with django framework (python). I have acces to it under address http://localhost:8000/. Now I want to share it over local network. I try to do it with Windows firewall Inbound/outbound rules, but it seems either I do something wrong or it's not enough.
To access a Django project running on a local network, you have to runserver with 0.0.0.0 as IP
python manage.py runserver 0.0.0.0:8000
and then set
ALLOWED_HOSTS = ["localhost", "yours_host_ip_aaddress"]
that should work if your firewall allows!
I am not sure how to suggest a duplicate question, but seems your question have an answer here. Basically, you need to ask the django program to accept connection from the outside world by
python manage.py runserver 0.0.0.0:8000

Database connection Error while hosting site on heroku

So I was trying to host my first Django app on heroku.
Took help form some Youtube channels. I used postgresql as my database. Now when I tried hosting my app on heroku the following error is showing up:
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?```
**This is the error showing**
run postgres -D /usr/local/var/postgres The result of this should be:
FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 379) running in data directory
"/usr/local/var/postgres"?
Then type kill -9 PID in HINT
Let me know if this works for you?