1

I have the identical problem to the question posed here: Django custom form ImportError even though file is in the same directory

This is from my urls.py in a django application:

import bulkEdit
...
...
urlpatters = patterns('',
    url(r'^engine/$', component_views.engine, name='engine'),
    ...
    url(r'^admin/', include(bulkEdit.urls)),

My bulkEdit.py file is in the same directory as urls.py.

The error I get is

  File "/home/context/work/riot/src/venv/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
ImportError: No module named bulkEdit

I get the same error if I try

from bulkEdit import urls as bulkEditUrls
...
...
urlpatters = patterns('',
    url(r'^engine/$', component_views.engine, name='engine'),
    ...
    url(r'^admin/', include(bulkEditUrls)),

bulkEdit is a file in the same directory as my urls.py file; file structure is

Rapier
|-component
|    |-__init__.py
|    |-admin.py
|    |-forms.py
|    |-models.py
|    |-views.py
|
|-Chassis
|    |-__init__.py
|    |-urls.py
|    |-bulkEdit.py
|    |-settings.py
|    |-views.py
|
|-manage.py

here is what I have tried so far (In all of these cases, 'Chassis' is in INSTALLED_APPS):

Using Python 2.7, so I get a syntax error with

import .bulkEdit

I've also tried:

url(r'^admin/', include(Chassis.bulkEdit.urls)),

gives me NameError: name 'Chassis' is not defined

url(r'^admin/', include("Chassis.bulkEdit.urls")),

gives me ImportError: No module named urls

url(r'^admin/', include("Chassis.bulkEdit")),

gives me ImproperlyConfigured: The included urlconf <module 'Chassis.bulkEdit' from '/home/userag/work/project/src/project/Chassis/bulkEdit.pyc'> doesn't have any patterns in it

url(r'^admin/', include(Chassis.bulkEdit)),

gives me NameError: name 'Chassis' is not defined

When I have

import bulkEdit
...
test = url(r'^admin/', include(bulkEdit.urls))

I get no error as long as it is not in the urlpatterns. When I add test to urlpatterns

urlpatterns = patterns('',
    url(r'^engine/$', component_views.engine, name='engine'),
    ...
    test

I get the error. Is there somewhere else I need to import bulkEdit due to me doing things with admin forms?

2
  • I get a syntax error with import .bulkEdit. It is a file in the same directory as urls.py Commented Dec 3, 2013 at 17:19
  • can you post your directory structure?? Commented Dec 3, 2013 at 17:22

4 Answers 4

4

Try relative import:

from .bulkEdit import urls as bulkEditUrls
Sign up to request clarification or add additional context in comments.

3 Comments

I get No module named bulkEdit
@AG did you add dot here: [.]bulkEdit?
yes, I made sure to include the dot; I get No module named bulkEdit
1

UPDATED : After comments

try: url(r'^admin/', include("Chassis.bulkEdit.urls"))

but first create the bulkEdit package and in there put the urls.py files. Then copy the code in bulkEdit.py to the

__init__.py 

file of the package in order to provide backward compatibility with other parts of your code.

The problem may has to do with the fact that bulkEdit.urls isn't a python module.

your dir structure after changes:

Rapier
|-component
|    |-__init__.py
|    |-admin.py
|    |-forms.py
|    |-models.py
|    |-views.py
|
|-Chassis
|    |-__init__.py
|    |-urls.py
|    |-bulkEdit
|        |-__init__.py     
|        |-urls.py     
|    |-settings.py
|    |-views.py
|
|-manage.py

6 Comments

If Chassis is an installed app try put it between '' characters. I mean: url(r'^admin/', include('Chassis.bulkEdit.urls')) or url(r'^admin/', include('Chassis.bulkEdit')) one of them has to work. See docs.djangoproject.com/en/dev/topics/http/urls
(sorry, formatting is lost)In all of these cases, 'Chassis' is in INSTALLED_APPS url(r'^admin/', include(Chassis.bulkEdit.urls)), gives me NameError: name 'Chassis' is not defined url(r'^admin/', include("Chassis.bulkEdit.urls")), gives me ImportError: No module named urls url(r'^admin/', include("Chassis.bulkEdit")), gives me ImproperlyConfigured: The included urlconf <module 'Chassis.bulkEdit' from '/home/userag/work/project/src/project/Chassis/bulkEdit.pyc'> doesn't have any patterns in it url(r'^admin/', include(Chassis.bulkEdit)), NameError: name 'Chassis' is not defined
After adding Chassis.bulkEdit to INSTALLED_APPS and creating __init__.py and urls.py inside the bulkEdit directory, I still get the error No module named bulkEdit. I think there is an intermediate step in django where I should be including bulkEdit, but have not.
When I do an include("chassis.bulkEdit.urls") in the python debugger, it shows `(<module 'chassis.bulkEdit.urls' from '/home/user/work/Rapier/src/Rapier/Chassis/bulkEdit/urls.pyc'>, None, None), so this file is able to find and recognise the bulkEdit module.
Ok, try this last thing: include("bulkEdit.urls") or include(bulkEdit.urls) without "" if that dont works, I give up. :D
|
1

The error was in my actual url pattern in bulkEdit/urls.py

urlpatterns = patterns('',
    (r'(?P<app_name>[^/])/(?P<model_name>[^/]+)-masschange/(?P<object_ids>[0-9,]+)/$', 'bulkEdit.mass_change_view'),)

should have been

urlpatterns = patterns('',
    (r'(?P<app_name>[^/])/(?P<model_name>[^/]+)-masschange/(?P<object_ids>[0-9,]+)/$', 'Chassis.bulkEdit.bulkEdit.mass_change_view'),)

The error of No module named bulkEdit originated from here.

Comments

0

But django actually imports your bulkEdit from other directory, and I suppose bulkEdit containing folder is not in sys.path (other option is absence of __init__.py), hence the error. As your application usually is in sys.path, you can try to specify

url(r'^admin/', include('Chassis.bulkEdit.urls'))

1 Comment

hhmm, when I use url(r'^admin/', include('Chassis.bulkEdit.urls')) I get a ImportError: no module named urls

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.