0

Is it possible to call function located in api.py file from models.py?

If so, what should be done to achieve the result?

1
  • Its just python, import the function and call it. Just be careful to avoid circular imports as the api often depends on the model. Commented May 28, 2015 at 15:59

2 Answers 2

1

You can use:

from my_app.api import my_function
Sign up to request clarification or add additional context in comments.

Comments

1

Yes you can do that easily depending on the location of api.py file.

1. At Same Level:

from api import desired_function

You can even use relative imports.

from .api import desired_function

2. In a different app:

from some_app.api import desired_function

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.