>From what i can understand, you want to test whether you can connect to database from your django project or not. If this is your need then try the following:
Go to the shell using following command: python manage.py shell On the shell, issue the following statements: from django.db import connection c=connection.cursor() I you don't get any errors, it means your DATABASE_SETTINGS are correct and you can go ahead and use your django models. If you get an error, it means there is some error in your DATABASE_SETTINGS and you need to rectify it before moving ahead. Thanks, Akshar On Fri, Oct 14, 2011 at 4:08 PM, Julian Hodgson < julian.of.lon...@googlemail.com> wrote: > I've go some python modules which automatically connect to the database > then they are loaded beacuse they have an __init__.py with > > from django.core.management import setup_environ > > import passion.settings > > def loadSettings(): > s = setup_environ(passion.settings) > print s > > # this should only be run from the workbox not on the server > loadSettings() > > This works fine even when it can't connect. > > But later if I do: > > from passion.cg.models import * > users = User.objects.filter( username='julian') > print users > > then I get > > # OperationalError: (1044, "Access denied for user ''@'localhost' to > database 'djangostack'") > # - [line 3] > > So I need a way to test the connection before trying to use the django > models. > > I can just check for exceptions, but is there a better way? > > Julian > > -- > 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 > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.