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

  • Home
  • SEARCH
  • 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 716019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:15:09+00:00 2026-05-14T05:15:09+00:00

My Django project’s directory hierarchy looks like this: + pybsd |—+ devices |—+ templates

  • 0

My Django project’s directory hierarchy looks like this:

+ pybsd
|---+ devices
    |---+ templates
    |---+ views
        |---+ interaction
            |---- __init__.py
            |---- geraete.py
            |---- geraetemodelle.py
            |---- geraetegruppen.py
        |---- __init__.py
        |---- ajax.py
        |---- html.py
        |---- misc.py
    |---- __init__.py
    |---- urls.py
|---- __init__.py
|---- urls.py

(Please excuse the German names. I preferred not to replace them here since it would add yet another possible error source when trying out the solutions you’ll hopefully suggest and answering your questions.)

Every request to http://URL/devices/.* is dispatched to the urls.py file living in /devices:

# ...
from views import html, ajax, misc, interaction

urlpatterns = patterns('', 
    # ...
    (r'^ajax/update/(?P<table>[a-z_]+)$', ajax.update),
    (r'^ajax/delete/(?P<table>[a-z_]+)$', ajax.delete),
    (r'^ajax/select_options/(?P<table>[a-z_]+)$', ajax.select_options),

    (r'^interaction/geraete/info/(?P<geraet>\d+)$', interaction.geraete.info),
    (r'^interaction/geraete/delete/(?P<geraet>\d+)?$', interaction.geraete.delete),
    (r'^interaction/geraetemodelle/delete/(?P<geraetemodell>\d+)?$', interaction.geraetemodelle.delete),
    (r'^interaction/geraetegruppen/delete/(?P<geraetegruppe>\d+)?$', interaction.geraetegruppen.delete),
    # ...
)

All URL definitions work except for those referencing the interaction package. I’m constantly getting the following error:

File "/home/simon/projekte/pybsd/../pybsd/devices/urls.py", line 33, in `<module>`
  (r'^interaction/geraete/info/(?P<geraet>\d+)$', interaction.geraete.info),
AttributeError: 'module' object has no attribute 'geraete'

I double-checked that the __init__.py files don’t contain anything.

Maybe you’ve already found the (Python- or Django-related?) mistake I made and am apparently unable to see. If not, read on. In any case, thanks for reading this long post!


Isolating the problem

1st test

It works if I provide the view functions as strings:

(r'^interaction/geraete/info/(?P<geraet>\d+)$', 'devices.views.interaction.geraete.info'),
(r'^interaction/geraete/delete/(?P<geraet>\d+)?$', 'devices.views.interaction.geraete.delete'),
(r'^interaction/geraetemodelle/delete/(?P<geraetemodell>\d+)?$', 'devices.views.interaction.geraetemodelle.delete'),
(r'^interaction/geraetegruppen/delete/(?P<geraetegruppe>\d+)?$', 'devices.views.interaction.geraetegruppen.delete'),

… or add yet another line to the imports:

from views.interaction import geraete, geraetemodelle, geraetegruppen

Using from views.interaction import *, however, doesn’t work either and results in the same error message.


2nd test

I created a file test.py in /devices:

from views import interaction
print dir(interaction)

Output:

simon@bsd-simon:~/projekte/pybsd/devices$ python test.py
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__']

Again, no sign of the modules I created in the interaction package (geraete.py, geraetemodelle.py, geraetegruppen.py).

Unlike in urls.py, trying from view.interaction import geraete, geraetegruppen, geraetemodelle in test.py results in ImportError: No module named view.interaction this time.


3rd test

I started the Django shell:

$ python manage.py shell
>>> import devices.views.interaction.geraete
>>> dir(devices.views.interaction.geraete)
['Abteilung', 'Auftrag', 'Auftragsvorlage', 'Geraet', 'Geraetegruppe', 'Geraetemodell', 'HttpResponse', 'HttpResponseBadRequest', 'HttpResponseRedirect', 'Raum', 'Standort', '__builtins__', '__doc__', '__file__', '__name__', '__package__', 'delete', 'info', 'models', 'move', 'render_to_response']
>>> 

$ python manage.py shell
>>> from devices.views.interaction import geraete
>>> dir(geraete)
['Abteilung', 'Auftrag', 'Auftragsvorlage', 'Geraet', 'Geraetegruppe', 'Geraetemodell', 'HttpResponse', 'HttpResponseBadRequest', 'HttpResponseRedirect', 'Raum', 'Standort', '__builtins__', '__doc__', '__file__', '__name__', '__package__', 'delete', 'info', 'models', 'move', 'render_to_response']
>>> 

$ python manage.py shell
>>> import devices.views.interaction
>>> devices.views.interaction.geraete
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'module' object has no attribute 'geraete'
>>> dir(devices.views.interaction)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__']
  • 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-14T05:15:09+00:00Added an answer on May 14, 2026 at 5:15 am

    When modules live in packages, and you import the package, Python does not automatically import all the modules in the package. Something in your program needs to import the modules you want to use. That can either be your urls module:

    import views.interaction.gaerete
    

    or, if you want interaction.garaete to always be available when you import interaction, it can be interaction/__init__.py:

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

Sidebar

Related Questions

I have worked a bit with Django and I quite like its project/applications model
In my Django project I am using Product.objects.all().order_by('order') in a view, but it doesn't
I've got a django project that contain some apps. The main urls.py includes the
I’ve got a brand new Django project. I’ve added one minimal view function to
I have a medium sized Django project, (running on AppEngine if it makes any
What is the best way to layout a large django project? The tutorials provide
There's no much documentation on how to deploy a Django project with Spawning and
I'm considering using Django for a project I'm starting (fyi, a browser-based game) and
My current project is in Rails. Coming from a Symfony (PHP) and Django (Python)
I'm just starting to use Django for a personal project. What are the pros

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.