views:

18

answers:

1

I have a django application xxx which does a number of things.

I also have a sepaerate application yyy. Which wants to call one of the functions of xxx.

Is there a way for me to import the functions?

For example, in yyy can i say

from toplevel.xxx import doit

Or what is the best approach, I dont want to duplicate code.

+1  A: 

Of course, you can fo it.

With a proper import and parameter, you can do it.

#app: app1
#someview.py

def a_view(request, someparam):
    #some code here


#app: app2
#otherview.py

from app1.someview import a_view

def another_view(request):
param = 1
a_view(request, param)

As for an example

UPDATE: Wish to mention that, your function a_view() do not have to get a parameter at all. So you can call functions with no paramaters. I just wish to mention that, if your function have paramaters, you have to pass them as if you do within an application.

FallenAngel