how to import functions of app from the same project from other app

219 views
Skip to first unread message

Asif Khan

unread,
May 21, 2018, 1:01:45 PM5/21/18
to Django users
I am trying to import function wrote in one of app in a project to import that function in other app in same project.

like I have one project and two apps.

Project1
           Project1
           accounts app (function written in this app)
           VV app (wants to utilize in this app)

I am new to Python and Django as developer.

Regards, Asif
      

Daniel Germano Travieso

unread,
May 21, 2018, 2:05:56 PM5/21/18
to Django users
Hello Asif!

To use a method from one app in another app would require you to import the app's module (using from - import statements), allowing the interpreter to know that the function from one scope is available on another.

In a serious note, I recommend that you first familiarize yourself with the Python language, maybe take a online course/tutorial about all its functionalities, and then go on to learning Django (maybe take the Django Documentation tutorial, it is really good).

I will leave you here some links to good resources for both beginner and advanced python and django.



Hope it helps!

Coder Dude

unread,
May 21, 2018, 3:18:49 PM5/21/18
to Django users
Suppose your function is in accounts.models . And you want to import in VV.views

In views.py of VV,
Write,
from accounts.models import foo

Asif Khan

unread,
May 21, 2018, 4:01:17 PM5/21/18
to Django users
thanks it is resolved.

Asif Khan

unread,
May 21, 2018, 4:02:05 PM5/21/18
to Django users
thanks yes I am doing day by day to improve python and django both.
Reply all
Reply to author
Forward
0 new messages