-4

Hello I have a Django project but I can't achieve to execute some functions. I precise I have a file in my app by the name of file2.py and I tried this :

import file2

And I got this :

No module named 'file2'

Could you help me please ?

Thank you.

Bruce Collins
  • 13
  • 1
  • 3

2 Answers2

1

If you have this file in the same directory, you can access it's functions like this: from .file2 import function

The dot is important, since it clarifies the path to the file

For example: you have defined some foo_form in your forms.py and you want to use it in your views.py, which is in the same directory as forms.py, your views.py should look like this:

from .forms import foo_form

def foo(request):

    form = foo_form()

If the file you want to import is in different directory though, you may want to check this question: Importing files from different folder

VooXe
  • 52
  • 7
0

Try to use this:

from .file2 import *

Can u post more information, such as the folder structure