#5534: stand-alone python script: no documentation avaliable
-----------------------------------------+----------------------------------
Reporter: anonymous | Owner: nobody
Status: closed | Component: Documentation
Version: SVN | Resolution: invalid
Keywords: python script stand-alone | Stage: Unreviewed
Has_patch: 0 | Needs_docs: 0
Needs_tests: 0 | Needs_better_patch: 0
-----------------------------------------+----------------------------------
Comment (by anonymous):
Replying to [comment:2 pytechd]:
> You can do this yourself easily:
>
> {{{
> #!python
> import os
> os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
> from django.conf import settings
> from myproject.polls.models import Poll
> }}}
>
> This has come up before so it should probably be added somewhere to the
documentation. If it's already there, I can't find it.
I tried some code, and the method that _works_ for me is:
First, set DJANGO_SETTINGS_MODULE:
{{{
#!python
export DJANGO_SETTINGS_MODULE=analitzador.settings
}}}
Secondly, write the script:
{{{
#!python
import os, sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
from django.conf import settings
from mysite.polls.models import Poll
#Anything you want:
print Poll.objects.all()
}}}
If the script is in the mysite directory, all work fun! (for example, if
mysite is in /home/user/mysite) but if script is in somewhere else, it
does not run (for example mysite is in /home/user/mysite and the script is
in /home/user/mysite/scripts)
How can I solve that?
Thanks,
Xan.
--
Ticket URL: <http://code.djangoproject.com/ticket/5534#comment:5>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" 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-updates?hl=en
-~----------~----~----~----~------~----~------~--~---