[Django]-Django custom form ImportError even though file is in the same directory

5👍

As far as I know there were changes in import system in Python 3. Just be more specific about what you want to import. I assume you want to import forms.py from contacts so

from contacts import forms

or you can try

import .forms
👤twil

0👍

It’s propper to do it like this:

from forms import FormClassName

Or you can

from forms import *

but it’s not nessesary.
From other apps you must

from contacts.forms import FormClassName # or wildcard '*'
👤McAbra

0👍

When importing the directory which python searches for import is project root and there is no module named as forms.

So if you wanna test create a file named forms in project root and it will import it.

That way following will surely work

from contacts.forms import FormClassName # or wildcard '*'
👤Nish

Leave a comment