Port doesnt respond - django

After python manage.py runserver , all goes well,when I use the link http://127.0.0.1:8000/ generated it fails to open the Django project on windows 10 completely, I can't figure out the problem. I've tried disabling proxies and firewalls and antivirus but still unable to open.Also tried restarting the computer and entire procedure,spent hours on this, what could be the problem

Related

View.py changes not updating on Django site

New Django user. Hello world. Got it to work. "Hello, world!" in the browser.
I went back into views.py and updated the line to read "Hello, world! You're at the index." and saved it. Refreshing the browser (F5) does not show the change. Even Ctrl-F5 doesn't refresh it.
I'm running ./manage.py runserver, and it recognizes that the file was changed and reloads the site:
/home/pi/pidjango/doorbell/views.py changed, reloading.
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
March 14, 2021 - 14:00:19
Django version 3.1.7, using settings 'pidjango.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
But refreshing the browser still shows the old line. I have to reboot the computer in order to see the change. But it does change, so I know the file is the correct one in the correct spot.
I'm not even sure what this is called. It's some kind of cache that's not flushing, so I researched Django caching and couldn't find anything that helped. I'm running '''DEBUG = True''', so you'd think this would be a pretty common thing to do.
This is on a headless Raspberry Pi, connected by SSH, so there's no local browser to try. I'm accessing it from the local network.
As it turns out, I was not using the Django server. I was using Apache2 on the Raspberry Pi. I should have known, since I was accessing the site at port 80.
Anyway, it works fine. Just need to restart Apache when the page is not refreshing.
sudo systemctl restart apache2

Django code not updating in server

I'm using Djnago 1.8.17. I have deployed the code to a remote server, checked that it is up to date, but the changes do not refresh in the web page.
Things I've tried so far:
Restarted gunicorn and nginx
Using manage.py instead of gunicorn
Clear memcached
Restarted server
Delete all .pyc files
Open in incognito
I've this module that is working fine in other servers, but for some reason this one is showing an old version.
The problem may come from static files
https://docs.djangoproject.com/en/1.8/ref/contrib/staticfiles/
you try to update them with
python manage.py collectstatic

Is there any well-known reason for this Django issue?

I created a django (1.8+) project some time ago, and it's weird that it works well with runserver, but it's not working with gunicorn (requests never end, nothing is received using curl or any browser to test my server). The funny fact is that it worked until recently (I'm in an AWS/AmazonLinux server; never changed the server image).
Since this timeout really annoyed me (and still does) I checked the project, opened a python interactive interpreter inside my virtualenv, and tried:
from my_project.wsgi import application
inside the appropiate folder (so this statement does not raise ImportError). But that single line took a lot (at least 10 seconds) to execute.
I think that is the reason why is gunicorn not working.
Is there any well-known reason this could happen? How can I debug further?
Edit My gunicorn command: gunicorn trescloud_landing.wsgi:application --daemon --bind=127.0.0.1:8888 --pid=/opt/webapps/pid/landing-pages.pid --access-logfile=/opt/webapps/log/landing-pages.access.log --error-logfile=/opt/webapps/log/landing-pages.error.log
Edit 2 Changed --timeout=600 (yes, 10 minutes) and gunicorn worked. But it is still troublesome to me that the server has a somehow low wsgi bootstrap

How do you keep a django digital ocean droplet live at all times?

If I purchase a droplet from digital ocean and install Django on it and get a basic hello world webpage going, how could I run this server and keep it live without a terminal staying open 24/7?
For example, if the droplet I.P. Address was 162.243.250.17:8001, and I entered this code:
python manage.py runserver 162.243.250.17:8001
I'll get the output:
Validating models...
0 errors found
January 31, 2014 - 22:58:23
Django version 1.6.1, using settings 'django_test.settings'
Starting development server at http://162.243.250.17:8001/
Quit the server with CONTROL-C.
But so how do I keep this going even if I close my terminal? I'm going to need a website to stay live.
UPDATE I found the solution
This is the first step if your production server/droplet is running Linux
in order for your website to go live as if it were production ready, you need to install nginx like this:
sudo apt-get install nginx
finally, get your home page to go live with a "Welcome to nginx!" like home page by entering this in your terminal:
sudo service nginx start
That's it!
The next step would be to make it so that the Django development server's address to replace the "Welcome to nginx!" page. I'm going to start working on that now, I'll keep this thread updated with the solution.
This is not the way to run django based webserver. You need to use apache/nginx.
If you use nginx you can combine it with wsgi container like gunicorn and supervisord.
For example, look here http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/ or search for these terms.
What eran said is absolutely right: you would never use the built in django server for anything in production, and use nginx or gunicorn/uwsgi.
However, you seem to be learning Django at this point. So, even if you just close the terminal (if you are SSH-ing) or close the browser, the program should run as long as you do not press ctrl + c, or kill the running server. However, you will find out that it crashes a lot and is very slow.
Learning nginx and uwsgi is too much work at this point. Learn django properly on your laptop first, and when you feel comfortable enough, then maybe deploy on digital ocean. Why spend money, albeit it is pretty cheap at $5.

bitnami django, solution to restarting service?

Hey I use installed bitnami django 1.3.0,
but whenever I add changes to urls.py or views.py in my system due to some error. The error won't disappear after refresh.
I have to restart my bitnami Service, "stop" and then "start" it, which is time consuming, I feel like I'm coding C# apps in visual studio. Sometimes even that doesn't work, I have to sometimes restart my computer and then I suddenly realize "oh wow, the error is solved now!"
Any solution to this? Why does everything require a runserver / restart?
You can use Apache for deploy your application in production but use the Django server for development. You will need to configure your application for being served by apache later (modifying the settings.py and the apache configuration file) but during the development you won't need to restart the server for every change.
Everything requires a restart because of the way that the python process operates. It does not reload the file when it's changed (outside of runserver..which is an anomaly, and just there for convenience)
Python execution isn't like PHP execution in that way, and your code isn't dynamically loaded on every page refresh, it's loaded on every server restart.
Hope that helps.