When I try to import something inside application:
from app_name.models import something
i have import error,
I must do it:
from models import something
This problem occurs only in one of many apps in project. What should I change?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s either what @Skirmantas suggested, that
app_nameis not on thePYTHONPATH, or you have a package clash, where some otherapp_nameis preceding yourapp_nameon thePYTHONPATH.My hunch is that it’s probably the latter, that you have an app that has the same package name as some other third-party app your using; I once had two top-level
registrationpackages on myPYTHONPATH.If you take my failure with the
registrationapp as an example, you’ll usually package your project something like this:It’s a community guideline that apps should be packaged to be “plug-and-play” compatible. They should be a top-level package and should be able to refer to intra-package resources through an absolute path like @Yuji suggested. If you like to ship and package your apps with your project, that means that in addition to
/myproject,/myproject/myprojectis also be on thePYTHONPATH. It’s even enforced in some cases.As I said, it’s just a hunch that you have clashing package names. If that’s the case, then after this long-winded post you should understand that the only option you have is to rename your package to something more unique, but I would never have the heart to just spill it out immediately to someone. It’s due to the sad truth that I’ve never found a more suitable name to replace
registration.