How? I have my django app in: /home/xan/anadoc/analitzador/
and my script in: /home/xan/anadoc/transformacions/script.py My script code is: import os, sys sys.path.append('/home/xan/anadoc/analitzador/') os.environ['DJANGO_SETTINGS_MODULE'] = 'analitzador.settings' from django.conf import settings from analitzador.analisi.models import Centre print Centre.objects.all() but when I run it, I get: python prova2.py Traceback (most recent call last): File "prova2.py", line 5, in <module> from analitzador.analisi.models import Centre ImportError: No module named analitzador.analisi.models but if I run in /home/xan/anadoc/ (super directory of my app) all works Thanks, Xan. On Oct 3, 6:12 pm, "Joseph Heck" <[EMAIL PROTECTED]> wrote: > just modify sys.path as you need... > > On 10/3/07, Xan <[EMAIL PROTECTED]> wrote: > > > > > Inhttp://code.djangoproject.com/ticket/5534there 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 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?hl=en -~----------~----~----~----~------~----~------~--~---