title: How to resolve `Requested setting INSTALLED_APPS, but settings are not configured.` error in Django?
body: <p>I have the following error when i run the <code>views.py</code> file. Note that it worked properly <strong>before</strong> I imported the <code>ratesEUR</code> model:</p>
  
  <p><strong>views.py (as per @sayse's reply):</strong></p>
  
  <pre><code>from django.shortcuts import render
  from models import ratesEUR
  import json
  import requests
  
  def my_view(request):
  
  response = requests.get("http://data.fixer.io/api/latest?access_key=XXX&amp;base=EUR")
  
      rates_EUR = json.loads(response.content.decode('utf-8'))
      timestamp = rates_EUR['timestamp']
      base = rates_EUR['base']
      date = rates_EUR['date']
      rates = rates_EUR['rates']
      id = 1
  
      rates_new = ratesEUR(id=id, timestamp=timestamp, base=base, date=date, rates=rates)
      rates_new.save()
  
      return response(data={})
  
  </code></pre>
  
  <p><strong>according error:</strong></p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Users\Jonas\Desktop\dashex\Quotes_app\views.py", line 2, in &lt;module&gt;
      from models import ratesEUR
    File "C:\Users\Jonas\Desktop\dashex\Quotes_app\models.py", line 4, in &lt;module&gt;
      class ratesEUR(models.Model):
    File "C:\Users\Jonas\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\base.py", line 103, in __new__
      app_config = apps.get_containing_app_config(module)
    File "C:\Users\Jonas\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\apps\registry.py", line 252, in get_containing_app_config
      self.check_apps_ready()
    File "C:\Users\Jonas\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\apps\registry.py", line 134, in check_apps_ready
      settings.INSTALLED_APPS
    File "C:\Users\Jonas\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\conf\__init__.py", line 79, in __getattr__
      self._setup(name)
    File "C:\Users\Jonas\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\conf\__init__.py", line 64, in _setup
      % (desc, ENVIRONMENT_VARIABLE))
  django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
  [Finished in 0.41s]
  </code></pre>
  
  <p><strong>models.py:</strong></p>
  
  <pre><code>from django.db import models
  
  
  class ratesEUR(models.Model):
      timestamp = models.CharField(max_length=10)
      base = models.CharField(max_length=3)
      date = models.DateField(auto_now=False, auto_now_add=False)
      rates = models.CharField(max_length=8)
  
      def __str__(self):
          return self.base
  </code></pre>
  
  <p><strong>settings.py:</strong></p>
  
  <pre><code>import os.path
  import os
  
  BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  
  
  # Static files (CSS, JavaScript, Images)
  # https://docs.djangoproject.com/en/2.2/howto/static-files/
  
  
  STATIC_ROOT = ''
  STATIC_URL = '/static/'
  STATICFILES_DIRS = (os.path.join('static'), )
  
  
  # Quick-start development settings - unsuitable for production
  # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
  
  # SECURITY WARNING: don't run with debug turned on in production!
  DEBUG = True
  
  ALLOWED_HOSTS = ["127.0.0.1", "locahost"]
  
  
  # Application definition
  
  INSTALLED_APPS = [
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      'Quotes_app',
      'Wiki_app',
      'rest_framework',
  ]
  </code></pre>
  
  <p><strong>Project dir:</strong> <br>
  <a href="https://i.stack.imgur.com/kGwHa.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kGwHa.jpg" alt="enter image description here"></a></p>
  
  <p><strong>What I have already tried:</strong></p>
  
  <ul>
  <li>Insert and save <code>export DJANGO_SETTINGS_MODULE=dashex.settings</code> to the bottom of the code in <code>venv/bin/activate</code> but I don't have such directory in myvirtualenv folder at all.</li>
  </ul>
  
  <p>Link: <a href="https://stackoverflow.com/questions/26082128/improperlyconfigured-you-must-either-define-the-environment-variable-django-set">ImproperlyConfigured: You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings</a> <br></p>
  
  <p>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;></p>
  
  <ul>
  <li>running <code>export DJANGO_SETTINGS_MODULE=dashex.settings</code>. This resulted in a syntax error within my shell.</li>
  </ul>
  
  <p>Link: <a href="https://stackoverflow.com/questions/57189162/improperlyconfigured-requested-setting-installed-apps-but-settings-are-not-con">ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured - Scraper</a> <br></p>
  
  <p>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;></p>
  
  <ul>
  <li>Inserted <code>DJANGO_SETTINGS_MODULE = DASHEX.settings</code> into my settings.py file according to the official Django documentation, but that didn't have any effect.</li>
  </ul>
  
  <p>Link: <a href="https://docs.djangoproject.com/en/1.10/topics/settings/#designating-the-settings" rel="nofollow noreferrer">https://docs.djangoproject.com/en/1.10/topics/settings/#designating-the-settings</a> <br></p>
  
  <p>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;>&lt;></p>
  
  <p>So where and how can I define <code>the environment variable DJANGO_SETTINGS_MODULE</code> as suggested in the error itself to -probably- resolve this issue?</p>
  
  <p><strong>In advance thank you very much for your assistance!</strong></p>