Tag Archives: flask app

flask-gentelella : A beautiful admin bootstrap for pythoners


Gentelella is a free to use bootstrap admin template for developing Python Flask web app, with custom Ajax libraries which includes variety of chart scripts like eChart, Morris Chart etc.

It packed with all must have AJAX and CSS libraries for a Python Web Geek

The bootstrap is also a ready to use flask app, all you need to do is customize the custom script. The app uses blueprint to organize flask routes, which is automatically created based on based on modules.

You can develop database powered app with less pain in few hours with this awesome bootstrap from Colorlib.

Clone and start using the project today

git clone https://github.com/afourmy/flask-gentelella.git
cd flask-gentelella

For instruction and the bootstrap project please visit GitHub page

Have a look at my demo app hosted on heroku.com which is not using any database, it depends on simple json API

How to pass python list to JavaScript in Flask app


You can’t use Python list directly into JavaScript, JavaScript lislt/array is not compatible with Python or wise versa. So what to do.

Solution

I have a list of names, which I want pass to a JavaScript in a Flask ninja template. Ninja template allow use to safely convert the python list to Json string then we can pass it to the JavaScript function / just JavaScript

<script type="text/javascript">

        dn = {{ distabr|tojson }}
</script>

You can’t use same route variable in multiple places in same template, it may not serve the purpose

In JavaScript Functions

Suppose you have separate JavaScript function files for some functionality like drawing analytic plots and pie diagram, or some donut chart. So how do we pass value to those functions ?

You can create a JavaScript as above, in your current template, then in function create a script variable to use it as follows.

function init_echarts() {
    var distNames=dn;
}

That’s all you need to know to embed some morris diagram to your flask app.

You should look at Morris JS , it is free and easy to use JavaScript charts library.