Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6649749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:48:40+00:00 2026-05-26T00:48:40+00:00

I have a project where the directory structure looks like: mywebsite/ manage.py __init__.py myapp/

  • 0

I have a project where the directory structure looks like:

mywebsite/
    manage.py
    __init__.py
    myapp/
        models/
            __init__.py
            base.py

myapp/models/base.py contains:

class X(object):
    pass

myapp/models/__init__.py contains:

from base import X

Now, if I do manage.py shell I can have the following session:

> import mywebsite.myapp.models
> import myapp.models
> mywebsite.myapp.models.X == myapp.models.X
False

However if I change myapp/models/__init__.py to be:

from myapp.models.base import X

Then I get True as expected.

I think I am missing something about how imports work or how Django changes paths when using manage.py shell.

Can anyone explain this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:48:41+00:00Added an answer on May 26, 2026 at 12:48 am

    When you open a Django shell, it adds the path to your project to sys.path. You can see this by running import sys; print sys.path on a Django shell and on a normal python shell and comparing the output. You will note that the output from the Django shell includes the path to the mywebsite directory as the first item of the list.

    Basically, it means that the two imports create two different module objects, since they are gotten from different points in the search path. The comparison check returns False since the module objects have different id’s (memory address)

    # These two values will be different
    id(mywebsite.myapp.models)
    id(myapp.models)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project with a directory structure that looks like: /foo/baz/__init__.py /bar/foo.py /bar/splat.py
I have a directory structure that looks like this: project/ __init__.py foo/ __init.py__ first.py
Part of my project directory structure looks like: \projects\project\main.R \projects\project\src where \src contains a
I have a python project with this directory structure and these files: /home/project_root |---__init__.py
I have a directory structure something like this: base subdir1 subdir2 subdir3 subsubdir1 subsubdir2
I have a project structure that looks like the following: [Solution Name] doc (documentation)
I have a Python project with following directory structure: /(some files) /model/(python files) /tools/(more
So I have a django project I just created called 'coolprojectsite' the directory structure
I have the following directory structure of a project: Folder project in Eclipse: --folder
OK, I have the following directory structure (it's a django project): -> project -->

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.