Sun 10 Feb 2008
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:
This may be used as follows:
Although I find the first version just more convenient and practical.
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/datesHere 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/nullFor it must be still added a code to views.py. The negative point in doing so is a unnecessary way through the web server.
http://www.server.com/update/?999 >>/tmp/dates
Although I find the first version just more convenient and practical.
English
Deutsch
Русский
(3 votes, average: 4 out of 5)
February 11th, 2008 at 6:13 p.m.
"Вот сам скрипт update.py, он должен находиться в папке проекта вместе с settings.py"
Необязательно. Достаточно указать путь к settings, чтобы можно было его подключить.
February 11th, 2008 at 7:37 p.m.
А еще можно свою команду для manage.py написать
February 12th, 2008 at 3:29 p.m.
Спасибо за предложения.
Насчет папки согласен, можно и path подключить, я всего-лишь показал один из возможных вариантов реализации.