On 08/09/06 17:56, Joe wrote:
> I would like to set up a python script that runs every night to send
> out an email subscription.  I would like to access a Django model that
> has the user's email addresses, as well as use the Django sendmail
> function.  Can someone help me understand what imports/path setup I
> have to do to get this working? (Note: I will not be setting up the
> Cron job, nor do I know now.  I will simply be giving a python script
> to our IT staff for them to set up).
> 
> Thanks for the help,
> 
> Joe
> 

%<------------------------------
#!/usr/bin/env python

import sys
sys.path.append('/path/to/django')
sys.path.append('/path/to/your/projects')

import os

# assuming /path/to/your/projects/myproject/settings.py
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'

from myproject.myapp.models import GreenStripedPotatoes

...

%<------------------------------

Alternatively you can add django and your projects folder to the 
PYTHONPATH, and define DJANGO_SETTINGS_MODULE as an environment variable 
before starting your script

e.g.:
$ export PYTHONPATH="$PYTHONPATH:/path/to/django:/path/to/your/projects"
$ export DJANGO_SETTINGS_MODULE="myproject.settings"
$ python /path/to/my/cronscript.py


The second method is more flexible as your sysadmin can write a shell 
script that sets up the environment and then runs your script. Like this 
  your script can be used on different servers without changing it.

hope this helps
cheers
Steven

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to