当前位置: 动力学知识库 > 问答 > 编程问答 >

django - ImportError(no module myapp.settings) while collecting settings.py variable on heroku, refering to local PYTHON environment on VENV (windows)

问题描述:

I need advice! I'm relatively new to django, and this is what happends on my well-working system, now that I'm interested in accessing variables in my settings.py file.

What I think is wrong is that my build somehow refers to my local python environement, and not the VENV I have installed on the project.

So I'm running this this in /myapp (problem also happends in all other dirs)

from django.conf import settings

import os

os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'

print settings.TRUSTPILOT_SECRET

And get the ERROR:

 Traceback (most recent call last):

File "C:\Users\Bc0655\approot\myapp\envTest.py", line 6, in <module>

print settings.TRUSTPILOT_SECRET

File "C:\Users\Bc0655\AppData\Local\Continuum\Anaconda2\lib\site-packages\django\conf\__init__.py", line 55, in __getattr__

self._setup(name)

File "C:\Users\Bc0655\AppData\Local\Continuum\Anaconda2\lib\site-packages\django\conf\__init__.py", line 43, in _setup

self._wrapped = Settings(settings_module)

File "C:\Users\Bc0655\AppData\Local\Continuum\Anaconda2\lib\site-packages\django\conf\__init__.py", line 99, in __init__

mod = importlib.import_module(self.SETTINGS_MODULE)

File "C:\Users\Bc0655\AppData\Local\Continuum\Anaconda2\lib\importlib\__init__.py", line 37, in import_module

__import__(name)

ImportError: No module named myapp.settings

This is what happends if I run the code in a shell on my VENV (is succesfull):

(venv) C:\Users\Bc0655\approot>python

Python 2.7.11 |Continuum Analytics, Inc.| (default, Jan 29 2016, 14:26:21) [MSC v.1500 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.

Anaconda is brought to you by Continuum Analytics.

Please check out: http://continuum.io/thanks and https://anaconda.org

>>> import os

>>> print os.environ['DJANGO_SETTINGS_MODULE']

myapp.settings

>>> from django.conf import settings

>>> print settings.TRUSTPILOT_SECRET

1234567890

>>>

But as you can see the error comes while running on my local anaconda installation.

And I do not think it is supposed to do that..

Here is more info about my setting:

**wsgi.py

import os

path = '/C:/Users/Bc0655/approot/'

if path not in sys.path:

sys.path.append(path)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")

from django.core.wsgi import get_wsgi_application

from whitenoise.django import DjangoWhiteNoise

application = get_wsgi_application()

application = DjangoWhiteNoise(application)

** parts of settings.py

INSTALLED_APPS = (

'django.contrib.admin',

'django.contrib.auth',

'django.contrib.contenttypes',

'django.contrib.sessions',

'django.contrib.messages',

#'whitenoise.runserver_nostatic',

'django.contrib.staticfiles',

'myapp',

)

WSGI_APPLICATION = 'myapp.wsgi.application'

ROOT_URLCONF = 'myapp.urls'

My directory goes like:

<approot>

| .env

| app.json

| manage.py

| requirements.txt

|<DIR> venv

|<DIR> myapp

|-----<myapp>

<DIR> migrations

settings.py

<DIR> templates

wsgi.py

__init__.py

分享给朋友:
您可能感兴趣的文章:
随机阅读: