You mean an error telling you that you need to set the
DJANGO_SETTINGS_MODULE environment variable? Or something else?
os.environ['DJANGO_SETTINGS_MODULE']='mysite.settings'
right at the top of your script (after the #! and the import for os ;) )
should solve this.
Then you should probably also add the parent directory of your project
to sys.path :-)
- Horst
Xan wrote:
> Hi,
>
> If we have the models models.py:
>
> from django.db import models
>
> class Poll(models.Model):
> question = models.CharField(max_length=200)
> pub_date = models.DateTimeField('date published')
>
> class Choice(models.Model):
> poll = models.ForeignKey(Poll)
> choice = models.CharField(max_length=200)
> votes = models.IntegerField()
>
> [example extracted fro http://www.djangoproject.com/documentation/tutorial01/]
>
> how can I write a python script for create various polls?
>
> I tried:
>
> a.py:
>
> #!/usr/bin/python
> from mysite.polls.models import Poll
> import datetime
>
> i = 0
> while i<4:
> a = str(i)
> print a
> Poll.create(question=a, data=datetime.date.today())
> i = i+1
>
>
> but when I run python a.py in bash, there are problems with imports.
> What lines of imports we need for running a standalone python script?
>
> Thanks in advance,
> Xan.
>
> PS: There is no doc in official site mentioning that. Maybe good to
> add it to site.
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---