Here is a small article on how to access the data directly, without request to the web server (e.g. for getting and/or updating of the data via cron).

This is how you can use a script launched from cron, for example, to regular writing some data in the file:
*/1 * * * * www /usr/bin/python /srv/project/update.py 999 >>/tmp/dates
Here is the script update.py, it must be in the project folder along with settings.py:
#!/usr/bin/env python

import sys,settings
from django.core.management import setup_environ
setup_environ(settings)
from YourApp.models import MyModel

try:
	print MyModel.objects.get(id=sys.argv[1])
except Exception:
	print "error"
There is shown the way of receiving data without request to the web server. You just have to activate the settings of Django project.

This may be used as follows:
*/1 * * * * www /usr/bin/wget -O /dev/null
http://www.server.com/update/?999 >>/tmp/dates
For it must be still added a code to views.py. The negative point in doing so is a unnecessary way through the web server.
Although I find the first version just more convenient and practical.

3 Votes | Average: 4 out of 53 Votes | Average: 4 out of 53 Votes | Average: 4 out of 53 Votes | Average: 4 out of 53 Votes | Average: 4 out of 5 (3 votes, average: 4 out of 5)
Loading ... Loading ...

Top Posts: