title: Django ImportError: No module named tango_with_django_project.settings
body: <p>From near the end of chapter 5 in the Tango With Django tutorial book, I have created a script used to populate a SQLite database with test data which is called:<br>
  <code>~/Workspace/wad2/tango_with_django_project/populate_rango.py</code><br>
  After receiving an error, I tried directly copy-pasting the script from the book and still received the following errors:</p>
  
  <pre><code>H:\Workspace\wad2\tango_with_django_project&gt;python populate_rango.py
  Traceback (most recent call last):
    File "populate_rango.py", line 7, in &lt;module&gt;
      django.setup()
    File "C:\Python27\lib\site-packages\django\__init__.py", line 22, in setup
      configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
    File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 53, in __ge
  tattr__
      self._setup(name)
    File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 41, in _set
  up
      self._wrapped = Settings(settings_module)
    File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 97, in __in
  it__
      mod = importlib.import_module(self.SETTINGS_MODULE)
    File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
      __import__(name)
  ImportError: No module named tango_with_django_project.settings
  </code></pre>
  
  <p><strong>populate_rango.py</strong></p>
  
  <pre><code>import os
  
  os.environ.setdefault('DJANGO_SETTINGS_MODULE',
                        'tango_with_django_project.settings')
  
  import django
  django.setup()
  from rango.models import Category, Page
  
  def populate():
  
      python_pages = [
          {"title": "Official Python Tutorial",
           "url":"http://docs.python.org/2/tutorial/"},
          {"title":"How to Think like a Computer Scientist",
           "url":"http://www.greenteapress.com/thinkpython/"},
          {"title":"Learn Python in 10 Minutes",
           "url":"http://www.korokithakis.net/tutorials/python/"} ]
  
      django_pages = [
          {"title":"Official Django Tutorial",
           "url":"https://docs.djangoproject.com/en/1.9/intro/tutorial01/"},
          {"title":"Django Rocks",
           "url":"http://www.djangorocks.com/"},
          {"title":"How to Tango with Django",
           "url":"http://www.tangowithdjango.com/"} ]
  
      other_pages = [
          {"title":"Bottle",
           "url":"http://bottlepy.org/docs/dev/"},
          {"title":"Flask",
           "url":"http://flask.pocoo.org"} ]
  
      cats = {"Python": {"pages": python_pages},
              "Django": {"pages": django_pages},
              "Other Frameworks": {"pages": other_pages} }
  
      for cat, cat_data in cats.items():
          c = add_cat(cat)
          for p in cat_data["pages"]:
              add_page(c, p["title"], p["url"])
  
      # Print out the categories we have added.
      for c in Category.objects.all():
          for p in Page.objects.filter(category=c):
              print("- {0} - {1}".format(str(c), str(p)))
  
  def add_page(cat, title, url, views=0):
      p = Page.objects.get_or_create(category=cat, title=title)[0]
      p.url=url
      p.views=views
      p.save()
      return p
  
  def add_cat(name):
      c = Category.objects.get_or_create(name=name)[0]
      c.save()
      return c
  
  # Start execution here!
  if __name__ == '__main__':
      print("Starting Rango population script...")
      populate()
  </code></pre>
  
  <p><strong>models.py</strong></p>
  
  <pre><code>from __future__ import unicode_literals
  from django.db import models
  
  class Category(models.Model):
      name = models.CharField(max_length=128, unique=True)
      views = models.IntegerField(default=0)
      likes = models.IntegerField(default=0)
  
      class Meta:
          verbose_name_plural = 'Categories'
  
      def __str__(self): 
          return self.name
  
  class Page(models.Model):
      category = models.ForeignKey(Category)
      title = models.CharField(max_length=128)
      url = models.URLField()
      views = models.IntegerField(default=0)
  
      def __str__(self): 
          return self.title
  </code></pre>
  
  <p><strong>settings.py</strong> (relevant code)</p>
  
  <pre><code>import os
  
  BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  TEMPLATE_DIR = os.path.join(BASE_DIR, 'tango_with_django_project', 'templates')
  STATIC_DIR = os.path.join(BASE_DIR, 'tango_with_django_project', 'static')
  MEDIA_DIR = os.path.join(BASE_DIR, 'tango_with_django_project', 'media')
  </code></pre>
  
  <p><strong>Locations</strong>  </p>
  
  <pre><code>~/Workspace/wad2/manage.py  
  ~/Workspace/wad2/tango_with_django_project/populate_rango.py  
  ~/Workspace/wad2/tango_with_django_project/settings.py  
  </code></pre>
  
  <p>Does anyone know what might be the cause of these errors?
  It seems that a common cause of this is the wrong folder name, but my script is in the <code>tango_with_django_project</code> folder which is specified in my <code>os.environ.setdefault</code> line already.
  If any other files would be useful, I can add them.</p>