Django RaspberryPi cannot connect to webserver - python

I'm following this website to connect raspberry pi with web server. All the steps are done correctly including the last one. Then I tried to go to http://127.0.0.1:8000/ but got this message from chrome:
"This site can’t be reached
127.0.0.1 refused to connect.
ERR_CONNECTION_REFUSED"
I didn't know what to do so just changed the last command into
python manage.py runserver 192.168.0.29:8000
(192.168.0.29 is my RPi inet address)
and then chrome threw this line:
"A server error occurred. Please contact the administrator."
meanwhile on RPi, it threw an
ImportError: No module named 'django.middleware.security'
How do I solve this problem? Thanks

Have you actually set up your django project by running django startproject? That should set up the file structure for you correctly and you should be able to then run manage.py runserver and see your project running with the admin services run from your ip/admin.

you should install django on your pi.
Using pip:
sudo pip install django
Using apt-get
sudo apt-get install python-django

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

Django 3.2.3 - 3.2.6 broken pipe error on dev server

I tried beget and digital ocean, different Django-projects (my own and examples) and every time i try to send request to server from my PC am getting
[05/Oct/2021 12:26:24,844] - Broken pipe from ('94.72.62.225', 53959)
I do same things every time:
python3 -m venv env
. env/bin/activate
pip install -r requirements.txt
python3 manage.py makemigrations
python3 manage.py migrate
set ALLOWED_HOSTS=['*'] in settings.py ( ALLOWED_HOSTS=['server_id'] also checked )
python3 manage.py rusnerver 0.0.0.0:8000
tools to send requests - google chrome, postman, curl
Found the problem. This issue only exists in devserver. The issue won't exist when you set DEBUG=FALSE. You are running a development server in production, don't do that. Here is a community tutorial which will guide you to set up Django with Postgres and Nginx: here in Production.
This issue was discussed and here's the ticket: django ticket.
In that ticket's comments, there is a quite clear explanation:
According to many sources the 'Broken Pipe' is a normal browser quirk. For example, the browser reads from the socket and then decides that the image it's been reading apparently didn't change. The browser now this (forcefully) closes the connection because it does not need more data. The other end of this socket (the python runserver) now raises a socket exception telling the program that the client 'Broke the socket pipe'.

Deploying Django on VPS but getting nginx 502 Bad Gateway: recv() failed (104: Connection reset by peer) while reading response header from upstream

I'm trying to deploy a Python3 Django project on a Digital Ocean droplet using one-click install for Django. I've uploaded everything and changed the files to what they should be (to my knowledge) but when I go to my site in my web browser, I get a page that says '502 Bad Gateway' from nginx. When I look in my error log, I get the following error:
recv() failed (104: Connection reset by peer) while reading response header from upstream
I'm not sure what this means exactly, so I'm hoping someone here can help. I have however changed the 'python' command to run python3 because it was set up for python2 and an older version of Django. By 'changing the command', I did the following:
Go to /usr/bin, remove python and pip, and create new links
ln -s python3 python
ln -s pip3 pip
I've updated Django and dependencies. Are the any config files I should edit? Perhaps a python path for nginx?
I'm a bit in over my head here, so any help is appreciated. Thanks!

Cannot connect to Heroku through cmd line

I have a Django project that I have deployed on a heroku web server and use PyCharm as my IDE. I used to be able to interact with my web server with "heroku run bash", however, now when I try running "heroku run bash" I get:
▸ stat /.local/share/heroku/client/bin/heroku: not a directory
▸ fork/exec /.local/share/heroku/client/bin/heroku: not a directory
I'm not sure what has changed, but I can't seem to connect to my heroku webserver anymore. I can still push changes using git push heroku master, but any other interaction with my heroku server doesn't seem to work anymore. I've already checked with Heroku and their systems are running just fine.
How do I reconnect to my heroku web server again with PyCharm? Or just in general?
Thanks in advance for your help!
This is either due to a new version of the CLI or to an OS upgrade.
I experienced the exact same issue on my Mac after upgrading to High Sierra and resolved it by reinstalling the CLI, this time using Homebrew.
Had the same problem. Did the following steps, as described here:
1) brew install heroku/brew/heroku
2) which heroku pointed to /usr/local/bin/heroku so no problems there
3) finally brew link --overwrite heroku
After this, everything was sorted and worked as expected.

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