0

I've used Django 1.3 for some time, and now that my system updated django automatically to 1.4, I'm facing a problem with a settings file. Problem 1: I have created new project with command django-admin.py startproject tutorial Django automatically created tutorial app inside tutorial project.I didn't want tutorial app so I deleted it, and now when I start development server here's the error:

 raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'tutorial.settings' (Is it on sys.path?): No module named tutorial.settings

Problem 2: I used to have one central settings file in root dir of a project(1.3), but it seems now that django doesn't even look at it if I have another app created.For example, In the previous problem, if I don't delete tutorial app, django will only look in settings file of that app and complain if I don't set database info there before start development server.If that is the case, what if I have 3 apps, do I need really for each of them to populate separate settings file with database info?

Zed
  • 5,683
  • 11
  • 49
  • 81

2 Answers2

4

Django 1.4 changed the file system layout of a Django project. The tutorial "app" you saw was not an app, but rather the project package. More information is available in the tutorial.

mipadi
  • 398,885
  • 90
  • 523
  • 479
  • I see, so I should keep that package and edit only settings file there? What is the point then of settings file in root dir, on this url isn't even mentioned but django-admin created it... – Zed Oct 23 '12 at 15:13
  • 1
    @Zed: There shouldn't be a settings.py file in the root, only in the project package. – mipadi Oct 23 '12 at 15:25
3

The Django 1.4 project structure changed -- for the better. It's much more modular now. The "tutorial" directory that was added inside is your project directory. It holds the settings.py, urls.py, etc. that are specific to your project. Apps are now added parallel to the project (in the main directory, at the same level as your "tutorials" project directory). This allows them to be imported through your project and apps as just the app, i.e. from some_app.models import SomeModel, instead of myproject.some_app.models import SomeModel. The benefits of this are obvious. Your app is no longer tied to a particular project. You could essentially rip it out as-is, package it for redistribution or use it in an entirely different project without having to make numerous changes, removing dependencies. Keep the new project structure and learn to love it.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444