How to clear all caches in Apache? - python

I have a django app running in a virtualenv on Windows 10 WSL1 (Ubuntu). The python version is 3.6.8.
When using the django development web server, python manage.py runserver, everything is fine. I access that with http://localhost:8000/<my app name>/
But when using apache2, version 2.4.29, months-old javascript code shows up in the browser debugger in a VMxxx file (though I haven't yet found an eval() that supposedly is the cause of the VMxxx being generated).
Also, old server-side code shows up: an old javascript error that resulted from the django python code sending the wrong content type - a bug that was fixed a couple of weeks ago.
I'm accessing apache2 with http://localhost/<my app name>/
I disabled mod_cache:
a2dismod cache
Module cache already disabled.
Also ran htcacheclean -r -l1k and manually looked at the page cache directory, which was empty.
I clear the Chrome cache on every page load, but also get the same errors when using a different browser (Firefox) that wasn't even installed when this old code that's showing up was written.
I put in a HTTP header to request no caching:
<meta http-equiv="Cache-Control" content="no-store" />
The closest thing to a cache that I have configured in Django settings is
SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db',
no CACHES settings.
And, of course, I stopped and restarted Apache.
service apache2 stop
service apache2 start
All to no effect.
Where is this old code coming from?

Duh! I had copied (not moved) the entire directory tree to a different location, but didn't update the apache2 configuration, so it was still pointing to the old location.
I'm leaving this up in case someone else makes the same mistake.

Related

Django - Apply changes in HTML & Static files without restarting dev server

I am working in a dev environment using the built in Django web server. One of the inconvenience that I have is everytime I make changes in HTML or Static files it does not apply when I reload the browser until I kill the dev server and run again.
python manage.py runserver localhost:8000
Is there a way so Django will reflect the changes instantly? Thanks in advance
Django reload the server only on changes on .py files. I read different ways to trigger reloading (such as installing a third party app, tweaking caching depending on whether DEBUG = True, etc etc).
The easiest and dumbest way is to make an insignificant slight change in the view you're working on (say, adding a #, removing it) after you edited and saved your template. It is dumb but it works.

Where is Flask running from on my OS X machine?

I'm used to building my websites with PHP, and on my OS X machine I expect to have to ensure that I have my scripts living in an explicitly specified location that I define as my Apache server's document root. But when I follow the simple instructions for building a Flask website, I magically get a working website, with nothing at all in any of the places on my machine that serve as document roots, regardless of where I have my Flask script. This is especially confusing since I always think if deployment as involving careful duplicating the file structure of my site under document root on the deployment server's document root.
Where is Flask "running from" on my OS X machine? Where do I "put it" when I deploy it (and what to I put)?
It's running from wherever you put it. You surely know where you saved the code: that's where it is.
But your mistake is in thinking that this development environment is running through Apache, or indeed has anything to do with how you'll run it in production. Neither is true. You're using a development server, the separate Werkzeug project, but that is not suitable for running in prod.
When you are ready to deploy, Flask has full instructions on how to either connect it to Apache through mod_wsgi, or set up a separate WSGI server which you'll usually connect to through a reverse proxy such as nginx.
Supposed you have your main.py under /path/to/my_project/, when you run the internal server python main.py, Flask is then running under your project folder.
Of course that built-in server is only good for development, when you're trying to deploy for production, normally Gunicorn (via wsgi app, read more HERE) or other web server is more appropriated (and advised by Flask) itself. And your production folder can be placed wherever you want, just like Apache PHP you may place your folder under /var/www/ (EDITED: as Daniel Roseman pointed out, you may try to change this folder location for security concern), it's the same for Flask, that's nothing stops you placing the folder but rather have the permission set properly.
Hope this helps.

django holding onto files in cache, delete view.py and view.pyc file, still runs

I've inherited a project which is a site running python/django. Having an issue where I believe Django is holding onto files in memcache (possibly).
It's a production server. There is currently no DEV environment (this is another matter).
I'm forced to make a requested emergency bug fix to the live site. BUT any modification to .py files are not reflected on the site. I can even delete a view.py (and view.pyc) entirely and the page merrily continues to load. I have looked into caching (https://docs.djangoproject.com/en/1.3/topics/cache/), and have added the appropriate dummycache line:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
}
}
I've tried forcing cache to 1 second:
CACHE_MIDDLEWARE_KEY_PREFIX = ''
CACHE_MIDDLEWARE_SECONDS = 1
CACHE_MIDDLEWARE_ALIAS = 'default'
Restarting nginx service does not help. I can run /etc/init.d/nginx restart and original files are still running after changes or being deleted completely. The only thing which forces the new files to be read and re-compiled to pyc is restarting the entire VPS instance! I can edit templates just fine and changes are reflected asap, its only py files not compiling to pyc.
Some other points:
I've also tried sudo /etc/init.d/nginx reload, no dice.
This is an AWS EC2 linux VPS its running python via nginx not apache
I've tried touch <project>/wsgi.py
Distro is CentOS release 6.5 (Final), so i've also tried sudo service nginx reload and sudo service nginx restart.
Is anyone please able to shed some light on this?
Edit: as a test, I've just deleted a critical view.py + view.pyc file to a sub section of the site, after 15 minutes, it is still running perfectly.
Edit2: i'm starting to think I'm simply meant to restart nginx in a different way. What should I be calling? Saving Changes To Django with Nginx?
Edit3: Based on IgnacioVazquez-Abrams help below, found that it was using uwsgi via ps -ef processes. I then found that it was using supervisor as a manager and all appropriate conf files looked fine. Then simply had to restart supervisor and BAM files updated instantly. Needless to say, this was stretching my knowledge of linux + python.
Based on IgnacioVazquez-Abrams help, found that nginx was using uwsgi to serve django, via ps -ef processes. After finding it was using uwsgi, and finding the uwsgi conf file i did a ack search for any references to loading the uwsgi file which found it in the supervisor conf file.
I then found that it was using supervisor as a manager and all appropriate conf files looked fine. Then simply had to restart supervisor and BAM files updated instantly. Needless to say, this was stretching my knowledge of linux + python.
It begs the question though, is there not an easier way to have files auto reload after a specified period or time, or is this crucial to improved performance of the python/django/nginx/uwsgi stack?

WSGI Application not found on OpenShift

I started from the Django template application in OpenShift, pushed it to OpenShift, and it ran without issue. After making a couple minor changes to settings.py and /.openshift/action_hooks/deploy, the application no longer runs (404 not found). In the command window, during deployment, I see CLIENT_ERROR: WSGI application not found. The build/deploy succeeds and finishes deployment.
As stated before, the home page now returns a 404. The logs indicate that application.py is not found. If I SSH into the deployment folder, I can find the file exactly where it is reported missing. Any ideas?
What changes did you make? If you changed the entry point you need to update your OPENSHIFT_PYTHON_WSGI_APPLICATION environment variable as per this release article: https://www.openshift.com/blogs/openshift-online-march-2014-release-blog

django 1.5 flips between "it worked" page display and error 500

Installed Django 1.5 python2.7 mod_wsgi and python-sql on a red hat 4 web server with apache 2.
The "It worked" page keep flipping between the correct display and "internal server error" "500"
The flip occurs very frequently when pressing F5, but not only when quickly sending a request.
I have restarted Apache, erased wsgi that was configured for python 3.2 and reconfigured and installed for 2.7. I have also tried creating a new project, mysql database, and kicking the cat < not advisable.
On the python 3.2 installation I was having problems with the admin page registrations flipping between what I had applied, and being non-existent.
This error is occurring with debug = true, no apps installed, no database configuration yet, and what I assume is a complete baseline system aside from the wsgi file which seemed to work fine for the 3.2 installation.
If you are getting issues with the Python egg cache, see the mod_wsgi documentation at:
http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Access_Rights_Of_Apache_User
The reason it flicks may be because you are running a multiprocess configuration and so requests can go to different processes. That it would be different though for different processes is a bit odd, but is often explained by import order dependencies in your code where whether it works depends on the order in which URLs are visited.
Quite often such ordering issues don't show up if using Django and developing with Django developer server, because the Django development server preloads code before requests are handled. I have commented on this specific Django issue in:
http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html
Do note that code examples in that corresponded to an old Django version so may not be appropriate to use now.

Categories