johnny wrote: > import re > from BeautifulSoup import BeautifulSoup > import urllib2 > from os import environ > #from settings import * > > def myfunction() : > > environ['DJANGO_SETTINGS_MODULE'] = "mysite.settings" > from settings import * > > I get an error: > myscript.py:22: SyntaxWarning: import * only allowed at module level.
right. import creates a namespace (like a var name) which wouldn't be well defined there. > > I have tried placing "from settings import *" above the "def > myfunction()", then I get an error: > raise EnvironmentError, "Could not import settings '%s' (Is it on > sys.path? > Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e) > EnvironmentError: Could not import settings 'mysite.settings' (Is it > on sys.path > ? Does it have syntax errors?): No module named mysite.settings > > If I don't do import *, what do I need to import in order to use > django model in a python script? Is it (settings.py) on sys.path ? (be sure to answer this question if you are still having problems.) > Import only the followings: > > DATABASE_ENGINE > DATABASE_NAME > DATABASE_USER > DATABASE_PASSWORD > DATABASE_HOST > DATABASE_PORT > you probably want something like this: # nifty trick to get ../settings import os, sys os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' BASE_DIR = os.path.dirname(os.path.abspath(__file__)) apppath=os.path.abspath(BASE_DIR+'/../') sys.path.insert(0, apppath ) import settings "like" being a key word, cuz that code works for me, it expects settings.py to be in a dir above it. Carl K --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---