rfeyer
Posts: 110
Joined: Sun Nov 23, 2014 9:25 pm

Calling app from within app

Sat Jan 02, 2016 1:09 pm

I am trying to find out if it is possible to call/ activate an app from within an app with Flask.

For instance, say you have app.py, which contains @app.route('/')
return render_template('login.html')
of course each containing appropriate def code etc.

So, these routes are able to call external templates/ HTML files.

is it possible to call an external python app?
I do have temps.py which calls temperatures from a ds18b20 sensor. I know I could put the code inside the main app, but would love to keep it separate and call upon it.

BTW - I will be calling the main app over LAN and Web

Any help would be appreciated,
Rainer

enedil
Posts: 80
Joined: Sat Feb 21, 2015 4:22 pm
Location: Toruń, Poland
Contact: Website

Re: Calling app from within app

Sat Jan 02, 2016 2:42 pm

Of course it is possible. But if the latter one is made with Python too, you could create module with it:
https://docs.python.org/3/tutorial/modules.html
- What Can a Thoughtful Man Hope for Mankind on Earth, Given the Experience of the Past Million Years?
- Nothing.

Kurt Vonnegut, Cat's Cradle

rfeyer
Posts: 110
Joined: Sun Nov 23, 2014 9:25 pm

Re: Calling app from within app

Sat Jan 02, 2016 3:45 pm

enedil,
that is exactly what I was looking for!!!! TY tons!

I did read through and, after reading about module paths, understand that one can alter the sys.path to include the containing folder.
Question: if the module is in the same folder as the parent app, will the path still have to be included in the sys.path file?

Again, TY for your help - this is already very useful!

Rainer

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: Calling app from within app

Sat Jan 02, 2016 4:10 pm

If it's in the same folder you don't need to do anything to sys.path.

One question, does your temperature code need to be run as root? I would think it's bad practice to run flask as root as it would create a security risk for your pi.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

rfeyer
Posts: 110
Joined: Sun Nov 23, 2014 9:25 pm

Re: Calling app from within app

Sat Jan 02, 2016 4:51 pm

very good question!

I had originally purchased DHT22's and used the Adafruit module (ah, there is the work module) but it does have to be run as root so I changed over to DS18b20's which do not. They are also water proof which I can use.
Took a while to get the code going (easy code, me inexperienced in python/Flask and had to search a bit) - but now it works :)
I should be able to do some trial and error this afternoon - will write back if it does NOT need a search path

TY again for your help!

Rainer

Return to “Python”