Include Custom Python Scripts to Plone views

I' currently using Plone 5.1 Version, if i want to include custom python script which can handle with different scenarios like,

  1. render pages
  2. external database connections
  3. Write queries to display the data in views/template

Simply my aim is to include one external project to plone pages.

If the above scenario is not possible how can i achieve such relevant things in plone cms.

Thanks in advance

Usually you create your custom addon, best using plonecli and add the templates and views/other Python code there.

For external database there are good basic integrations to build on, like

You usually make a view/template by having one .py file and one .pt file. If you use plonecli, this will be set up automatically for you.

It will also include an example of how to display the data.

It will be something like this:

in template.pt

<h1>${context/Title}</h1>
<p>${view/some_calculation}</p>

h1 will be the title of you content type (if you need that)
p will be content of what is returned from view.py

def some_calculation(self):
     … a lot of calculations here
    return 'this is the sum'

It is also possible to make views with just one of the files (just template.pt or view.py) if you really want to .