1

I want to be able to call a function in Python/Django by a string.

For example say I have two apps in my django project....

AppOne
AppTwo

Now say that AppOne has a function that follows this format...

def ShowMe(request):
    pass

Now say that AppTwo has a function exactly like AppOne's function, but pretend that it does some inner operations slightly differently...

Now say that I'm in AppTwo, and I want to call AppOne's ShowMe function.... NOT AppTwo's ShowMe function

Is there anyway for me to (without actually importing the app using import) run a function from another App if multiple apps have the same function name by specifying an App Name when I get the function?

I'm using Django 1.8.4

Ricky
  • 41
  • 1
  • head over the http://stackoverflow.com/questions/4246000/python-calling-functions-dynamically – Ekin Ertaç Dec 22 '15 at 05:55
  • 1
    What problem are you trying to solve by not importing the app? There are functional wrappers to the `import` behavior which can help in some situations, but ultimately you have to create the function object somewhere. The `import` keyword is the usual mechanism but not the only one, if you're really in a special situation. Also, which version of Python are you using? The `importlib` wrapper is a lot more developed in 3.x than 2.7. – Peter DeGlopper Dec 22 '15 at 06:24
  • I don't know what you are trying to do here, but to answer your question directly; you can simply call the URL for that function (since its a view method). That will "trigger" that function to work - but please explain what is the problem you are trying to solve by not importing the method. – Burhan Khalid Dec 22 '15 at 06:28
  • I want to be able to call a specific applications Render function from a global render function.... For example if I try to visit a webpage like /demo/ I want to run the Demo applications Render function. – Ricky Dec 22 '15 at 08:06
  • And why don't you want to do something like `import demo`? That's the unusual part. – Peter DeGlopper Dec 22 '15 at 20:16

0 Answers0