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 9272085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:46:59+00:00 2026-06-18T15:46:59+00:00

I have a Django project. A part from this Django project was a reporting

  • 0

I have a Django project. A part from this Django project was a reporting module that searches for reports directory inside all INSTALLED_APPS, very similar to autodiscover mechanism of the admin interface.

This module had a small registery class that registers classes found. In a very simplified way it looks something like this:

def autodiscover():
    """
    Searches for reports module in all INSTALLED_APPS
    """

    global REPORTSLOADING
    if REPORTSLOADING:
        return
    REPORTSLOADING = True

    import imp
    from django.conf import settings

    for app in settings.INSTALLED_APPS:
        try:
            app_path = import_module(app).__path__
        except AttributeError:
            continue

        try:
            imp.find_module('reports', app_path)
        except ImportError:
            continue

        import_module("%s.reports" % app)
    REPORTSLOADING = False

class ReportsRegistery(object):
      .....

registery = ReportsRegistery()

If any of the INSTALLED_APPS need to register a Report class, we need a line inside reports/__init__.py:

import reports
reports.registery.register(SomeReportClass)

And inside the main urls.py i would do:

import reports
reports.autodiscover()


urlpatterns = patterns('',
....

 (r'', include(reports.registery.urls)),
)

Now I decided to create a pluggable django application for it and placed the same code in __init__.py of the package. The problem I am facing is that reports module with the new structure gets imported twice, thus causing the recreation of the ‘registery’ object. So, no urls are actually registered. It’s loaded one time from the import inside urls.py (as expected) and another one initiated by autodiscover. I have verified this by:

print hex(id(registery))

and found out it returned 2 different values.

I thought that the reports package will be imported once just like when it was just a module.

How can I prevent it from being loaded twice ? Or how can I ensure that we will have only one ReportsRegistery instance to work with ?

  • 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-06-18T15:47:01+00:00Added an answer on June 18, 2026 at 3:47 pm

    It’s not uncommon for Django to import modules twice. There are two reasons for this:

    1. The classic Django project layout encouraged you to have your working directory on the path twice at two different locations. This meant you could import something as project.module, or as app.project.module, which would confuse the import machinery.

    2. The settings.py file is actually imported twice.

    Fixes:

    1. Double-check that all of your imports use the same style of path.

    2. Don’t import your module from settings.py

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my django project, I have 4 models that are all tied together in
I have inherited a Django project that needs i18n. I have done all the
I have a django project that I have been working on as a solo
I have a django project which is laid out like this... myproject apps media
I have a django project that runs on a Linux server, and I've been
So I have a django project I just created called 'coolprojectsite' the directory structure
In my current django project I have a model that stores very long strings
I want to have 2 separate admin sites inside a Django project. By separate
I'm doing the Django tutorial, part 3: https://docs.djangoproject.com/en/dev/intro/tutorial03/ I currently have this text in
I have an application built with Django. Part of it relies on data that

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.