Import custom module to Django

Question:

I’m making a django app and cannot import a custom module inside the views.py file.

I’m trying to import class "Integrate" from auth.py inside modules folder from integrations/views.py

I tried placing __init.py__ inside the app folder and modules folder but still doesn’t work.

enter image description here

views.py:

from ..modules.auth import Integrate

Powershell:

from ..modules.auth import Integrate
ValueError: Attempted relative import beyond toplevel package
Asked By: Biswajit Chopdar

||

Answers:

I do this a lot in my projects. Creating custom modules and importing them.

Try this:

from modules.auth import Integrate
Answered By: nik_m

You can use this :

from .models import Integrate

It will be work for use models

Answered By: Omid Reza Heidari

I am pretty certain I had this exact problem.
It helps if you make the directory holding the module a ‘Sources Root’
You right click on the directory and down the bottom of the pop-up is ‘Mark Directory As’ option.
AFAIK this adds that directory to the PythonPath so the module in there will be found.

Answered By: fred tingey
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.