3

i am trying to import the client in django for testing. but when i do, i get this wierd error:

ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

from django.utils import unittest
from django.utils import simplejson as json
from django.test.client import Client

this is how i imported the client so that i could use it for testing. can someone explain this to me please.

LemonPie
  • 806
  • 1
  • 11
  • 23

3 Answers3

5

Try this:

import os
import sys

sys.path.append('/home/username/www/site_folder')
os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings'


from django.utils import unittest
from django.utils import simplejson as json
from django.test.client import Client

But replace project with folder name, where your settings.py is

imkost
  • 8,033
  • 7
  • 29
  • 47
  • add this to where i am importing the client or in my settings.py – LemonPie Feb 18 '13 at 22:50
  • i get this when i do that: "ImportError: Could not import settings 'mysite.settings' (Is it on sys.path?): No module named mysite.settings" – LemonPie Feb 18 '13 at 23:29
4

The Client is looking for the settings.py. You could simply load the client by typing this in your project folder:

python manage.py shell
Thomas Schwärzl
  • 9,518
  • 6
  • 43
  • 69
0

In Pycharm which I use, after following this Running Django tests in PyCharm my problem was solved.

It's in the file > settings > Django Support, and then select the right settings.

Community
  • 1
  • 1
shellbye
  • 4,620
  • 4
  • 32
  • 44