python 3.x - Import django setting in a app for test -


i import django setting in api_script.py in api settings in agora.settings :

here api_script.py in api :

import os os.environ.setdefault("django_settings_module", "agora.settings") django.contrib.auth.models import user import django django.db.models.loading import cache model_cache profile.models import profile_user try :     django.setup() except :      pass  def check_profile_exist(token):     print(token) 

here error :

traceback (most recent call last):   file "/home/bussiere/workspacesafe/agora/api/api_script.py", line 3, in <module>     django.contrib.auth.models import user   file "/usr/local/lib/python3.4/dist-packages/django/contrib/auth/__init__.py", line 7, in <module>     django.middleware.csrf import rotate_token   file "/usr/local/lib/python3.4/dist-packages/django/middleware/csrf.py", line 14, in <module>     django.utils.cache import patch_vary_headers   file "/usr/local/lib/python3.4/dist-packages/django/utils/cache.py", line 26, in <module>     django.core.cache import caches   file "/usr/local/lib/python3.4/dist-packages/django/core/cache/__init__.py", line 34, in <module>     if default_cache_alias not in settings.caches:   file "/usr/local/lib/python3.4/dist-packages/django/conf/__init__.py", line 48, in __getattr__     self._setup(name)   file "/usr/local/lib/python3.4/dist-packages/django/conf/__init__.py", line 44, in _setup     self._wrapped = settings(settings_module)   file "/usr/local/lib/python3.4/dist-packages/django/conf/__init__.py", line 92, in __init__     mod = importlib.import_module(self.settings_module)   file "/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module     return _bootstrap._gcd_import(name[level:], package, level) importerror: no module named 'agora' 

and here tree file :

.     ├── agora     │   ├── __init__.py     │   ├── __pycache__     │   │   ├── __init__.cpython-34.pyc     │   │   ├── settings.cpython-34.pyc     │   │   ├── urls.cpython-34.pyc     │   │   └── wsgi.cpython-34.pyc     │   ├── settings.py     │   ├── urls.py     │   └── wsgi.py     ├── api     │   ├── admin.py     │   ├── api_script.py     │   ├── __init__.py     │   ├── migrations     │   │   ├── __init__.py     │   │   └── __pycache__     │   │       └── __init__.cpython-34.pyc     │   ├── models.py     │   ├── __pycache__     │   │   ├── admin.cpython-34.pyc     │   │   ├── api_script.cpython-34.pyc     │   │   ├── __init__.cpython-34.pyc     │   │   ├── models.cpython-34.pyc     │   │   └── views.cpython-34.pyc     │   ├── tests.py     │   ├── unit_test.py     │   └── views.py     ├── contact     │   ├── admin.py     │   ├── __init__.py     │   ├── models.py     │   ├── __pycache__     │   │   ├── admin.cpython-34.pyc     │   │   ├── __init__.cpython-34.pyc     │   │   └── models.cpython-34.pyc     │   ├── tests.py     │   └── views.py     ├── dockerfile     ├── generateadm.py     ├── img_20150928_105102.jpg     ├── __init__.py     ├── manage.py     ├── message     │   ├── admin.py     │   ├── __init__.py     │   ├── models.py     │   ├── __pycache__     │   │   ├── admin.cpython-34.pyc     │   │   ├── __init__.cpython-34.pyc     │   │   ├── models.cpython-34.pyc     │   │   └── views.cpython-34.pyc     │   ├── tests.py     │   └── views.py     ├── mock     │   ├── admin.py     │   ├── __init__.py     │   ├── models.py     │   ├── __pycache__     │   │   ├── admin.cpython-34.pyc     │   │   ├── __init__.cpython-34.pyc     │   │   ├── models.cpython-34.pyc     │   │   └── views.cpython-34.pyc     │   ├── tests.py     │   └── views.py     ├── profile     │   ├── admin.py     │   ├── __init__.py     │   ├── models.py     │   ├── profile_script.py     │   ├── __pycache__     │   │   ├── admin.cpython-34.pyc     │   │   ├── __init__.cpython-34.pyc     │   │   ├── models.cpython-34.pyc     │   │   └── profile_script.cpython-34.pyc     │   ├── tests.py     │   └── views.py     ├── queue     │   ├── admin.py     │   ├── __init__.py     │   ├── models.py     │   ├── __pycache__     │   │   ├── admin.cpython-34.pyc     │   │   ├── __init__.cpython-34.pyc     │   │   └── models.cpython-34.pyc     │   ├── tests.py     │   └── views.py     ├── requierement.txt     ├── result.txt     └── runserver.sh 

regards , thanks

have appended django project path python's path?

e.g.

import os, sys base_path="/location/folder/where/manage.py/lives" sys.path.append(base_path) os.environ['django_settings_module'] = 'agora.settings' 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -