View.py changes not updating on Django site - django

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

Related

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.

django-rosetta not saving translations on hitting "Save and Translate next block" in Chrome

django-rosetta is not saving the translations on hitting "Save and Translate next block" in Chrome.
It seems to be working fine in Firefox though. I tried clearing cache so that does not seem to be an issue.
On Chrome, after entering translated text and hitting the "Save.." button, I'm redirected to the main screen without my changes being saved.
I updated to the most recent version of rosetta thinking that the Issue13 fix would solve my problem but it does not.
I've also made sure that my .po and .mo files have 777 permissions.
Been a long time, not sure if you were able to sort it out?
I have a dev environment running Django 1.4.2 and Rosetta 0.6.8 on Lion and it works flawlessly. Im setting it up with the python manage.py runserver command.
Then when I wanted to deploy it to my Ubuntu 12 server Rosetta started to behave quite weird. I installed Nginx as a proxy and was running apache with wsgi. Same versions besides that. It was not just the translated strings that were not being saved but the navigation became absolute random. Did not matter what button I pressed, I suspected the proxy configuration wasn´t setup properly since I could run it locally in my dev.
To make a long story short, I finally shutdown nginx and apache and just ran django with the builtin and hence got the django logs in my terminal. It got a lot of errors that made the server restart itself every few seconds. This obviously explained the somewhat non-reliable behavior of the app. I dumped the database in production and resynced it. Now when I runserver in production it works just as good as in my dev. When I plug in apache to do the job (going around nginx for the moment) the problem still persist, not as bad as before though. Browser does not make any difference.
One of the errors that did pop up was this
Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x1781710>>
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/apport_python_hook.py", line 50, inapport_excepthook
if not enabled():
TypeError: 'NoneType' object is not callable
Still havent solved this but will be posting the solution when I do.
EDIT:
Scratched the good ol´ apache wsgi setup and went for Gunicorn instead. Works really well now, not sure what that was all about but I´m quite happy with the new setup anyways.
Here´s a good setup guide
http://ijcdigital.com/blog/django-gunicorn-and-nginx-setup/
hopefully this helps someone in the future!

Django Apache2 mod_wsgi flatpages admin not working

I finally got apache2 with mod_wsgi working on Linux (havent much luck with windows :D) and everything works fine, but now when I added flatpages to my project, I found out that Apache doesn't seem to be aware of URL for admin when trying to create new flatpage via admin.
It says
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1/admin/flatpages/flatpage/1/
And now I noticed that when I'm on admin front page, and hit F5 again and again, flatpages admin appears and disappears, but nothing like this happens when using dev server, so I'll try to create new project with default setting and see what it'll do in apache and in dev server, did anyone came across this kind of error?
The Django dev server auto-reloads your code when you change it, but Apache does not.
If you are running mod wsgi in daemon mode, you can reload the code by touching the wsgi script.
touch myproject/mysite.wsgi
Otherwise, you may have to restart apache. For example
/etc/init.d/apache2 restart

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.