just modify sys.path as you need...

On 10/3/07, Xan <[EMAIL PROTECTED]> wrote:
>
> In http://code.djangoproject.com/ticket/5534 there is a howto for
> doing that.
> But it's only when the script is in the root project directory.
> What happens if we want the script in other location? What line we
> have to add?
>
> Thanks a lot,
> Xan.
>
> On Sep 18, 8:27 pm, Horst Gutmann <[EMAIL PROTECTED]> wrote:
> > 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 yourscript(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 
> > > frohttp://www.djangoproject.com/documentation/tutorial01/]
> >
> > > how can I write apythonscriptfor 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 runpythona.py in bash, there are problems with imports.
> > > What lines of imports we need for running a standalonepythonscript?
> >
> > > 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to