mcd
mcd

Reputation: 7136

django import project.app vs import app

I am going through another django tutorial and I noticed for the imports the author uses from project.app.file import item but this doesnt work unless I do from app.file import item

Example: Authors version:

from ecomstore.catalog.models import Product

which doesnt work Error: ImportError: No module named catalog.models

but this does

from catalog.models import Product

I am just why the authors version doesnt work for me and why and if there is a setting I can change to fix this so its easier to follow along.

I am seeing this as an issue in following along and trying to understand how django works this and where the settings or configurations for this resides where I can change within my project.

Thanks

Upvotes: 0

Views: 358

Answers (2)

Edward Liang
Edward Liang

Reputation: 100

Per the date, I think you're using newest django 1.4, which has a new layout when you typed "django-admin.py startproject" and "django-admin.py startapp".

https://docs.djangoproject.com/en/1.4/releases/1.4/#updated-default-project-layout-and-manage-py

Upvotes: 0

Otskimanot Sqilal
Otskimanot Sqilal

Reputation: 2402

from catalog.models import Product is fine, and i think it's better than the example. Because if you want to use the app, you have to change every single import statement where you use your project name. Don't do from myproject.myapp.models import MyModel, it's a bad practice, if you're sure that the models you importing is in the same directory, i think this one is the best : from models import Product, else from myapp.models import MyModel

Upvotes: 1

Related Questions