first_on_colour

Run Python Through Filemaker Using Web Viewer

Discussion created by first_on_colour on Dec 18, 2018
Latest reply on Dec 19, 2018 by eric

IMPORTANT: I'm on Linux, this may be different for you, I expect that you have an understanding of Python, Linux, Virtualenv, these tutorials are quick, dirty, and to the bone, no fluff involved.

 

Tutorials I'm making after this one (NOTE, these one's won't be done today):

- Sending large amounts of data through the Python server using XMLHttpRequests.

 

Part 1: The Setup!

For this example I'm going to be using Flask to create the web server, I recommend using Amazon Web Services to host the server however you can use any service you would like.

Depending on your distribution you may need to use another command (that is below this one).

$ virtualenv env

OR $ virtualenv -p /usr/bin/python3 env

$ . ./env/bin/activate.sh

You are now using a python virtual environment, you can use

$ deactivate

to exit the virtual environment.

Now we need to install Flask (since that is what I'm using for this guide).

If you had to type "-p /usr/bin/python3" use the command after this one.

$ pip install Flask

OR

$ pip3 install Flask

Now to make the folders

$ mkdir templates

 

Part 2: Making The Python Script

I'm going to call my application application.py, just remember that we will be using the application name to run the program through flask.

You may hate me for this however I'm just going to screenshot the code since I feel that's the best way to format it. I am only going to explain one part of the code since I expect you to know Python.

2018-12-18_11-43.png

@app.route('/<celsius>')

This is how Flask routes url addresses, this is how we get Filemaker to send data to python without using Javascript.

We can also send more data via a url via base64 and xzip however I will be showing that in a later tutorial.

Part 3: The HTML

I don't truly need to explain the HTML other than the fact that we are using Flasks HTML rendering language (which is fairly self-explanitory.

Create a file called "index.html" in the "templates" folder and put the following inside the file.

<!DOCTYPE html>

<html lang="en-US">

<head>

<meta charset="utf-8" />

 

<title>Temperature Converter</title>

</head>

<body>

{% if temp %}

<h1>{{ temp }} F</h1>

{% endif %}

</body>

</html>

Part 4: Running The Application.

Simply

$ python application.py

Part 5: Setting Up Filemaker

Set the Web Viewer to use a "Custom Web Address" and put

"http://YourIPAddress:5000/" & Table::data

Part 6: Party!

Filemaker is now using Python to convert temperature!

 

I know this was a pretty bland tutorial without much use however the next tutorial is a big one and has many uses, such as adding the ability to integrate Tensorflow into Filemaker via the Web Viewer.

 

If you need any help or assistance with this, please let me know! I'm always glad to help, just keep in mind that I don't have Filemaker at my home.

Outcomes