24 March 2020 Updated 25 March 2020 by Peter
post main image
Flask is hot. Everyone loves Flask. I believe the main reason is that it is so easy to start with Flask. You create a virtual environment, copy-paste a few lines of code from some example, point your browser at 127.0.0.1:5000 and there is your page. Then you hack a little with a Jinja template and you get a beautiful page. You can even run Flask on a Raspberry Pi, isn't that wonderful? My main reason ...
Read more
10 March 2020 Updated 11 March 2020 by Peter
post main image
The problem: a customer wants an application with a certain functionality and want this yesterday. What you do is look for a plug-and-play solution, libraries and/or extensions. You tell your customer that you can do it, customer is happy, you do it. For example, you take Wordpress, select and configure some plugins. Problem solved, or is it? Yes, the problem is solved but for how long? After some ...
Read more
29 February 2020 Updated 29 February 2020 by Peter
post main image
I never really checked if CSRF protection was working in my Flask application, this website. Is it enabled by default? From the Flask_WTF extension documentation: Any view using FlaskForm to process the request is already getting CSRF protection. And from the text of Miguel Grinberg's post 'Cookie Security for Flask Applications': If you are handling your web forms with the Flask-WTF extension, ...
Read more
22 February 2020 Updated 22 February 2020 by Peter
post main image
While working on comments system for the first time I bounced into the problem of having multiple WTForms forms on a single page. On every page there also is the search form but this is not a POST form. It is doing a GET. The comments system uses two forms: Comment form Comment reply form The comment form is immediately below the content item, blog post or page, the comment reply form is initially ...
Read more
15 February 2020 Updated 18 February 2020 by Peter
post main image
I hoped to tell you today that you could comment on the blog posts of this website now. That would have meant that I completed the first implementation of the comments system. Unfortunately I stumbled upon some problems, yes of course, I am a programmer, and one of them involved the TextAreaField. I just wanted a simple extended version of the WTForm TextAreaField, just add a character counter field ...
Read more
8 February 2020 Updated 16 February 2020 by Peter
post main image
Now that I have blog posts, pages and a contact form, I decided to implement the comments for the blog posts and pages. Not just flat comments but threaded comments, also called nested comments. Some months ago I read about this and I really liked Miguel Grinberg's article: Implementing User Comments with SQLAlchemy. As often Miguel starts with defining the problem and some hard core theory and explaining ...
Read more
30 January 2020 Updated 30 January 2020 by Peter
post main image
When you start with Flask you read a bit about the Application Context, TL;DR. Do not know about you but I certainly did not understand it fully. What is app, what is current_app, what is the difference, you just start programming your application. All the time in the background there is this weird buzz: what exactly is the Application Context ... Then at a certain moment when using a class you instantiated ...
Read more
24 January 2020 Updated 24 January 2020 by Peter
post main image
When you sign up for this website you are assigned an avatar image. Of course you can change the avatar in 'your account' and this is done using an image picker. Many image pickers examples can be found on the internet. But this is a Flask site including WTForms and I want the image picker to be generated by the wonderful Jinja macro I am using, see also link below, ok, I modified it a bit. With this ...
Read more
13 January 2020 Updated 13 January 2020 by Peter
post main image
Time for joy or crisis: running the OWASP Zed Attack Proxy (ZAP) application to check vulnerabilities of our web application. Developers often know there are weak points in their code, but there always is a date of delivery. So why not use a tool that list the well-known and  important ones? This is my first time using ZAP so if are an expert you best stop reading here. In the links below there ...
Read more
6 January 2020 Updated 9 January 2020 by Peter
post main image
This Flask website is multilanguage. The implementation is described in previous posts. So far all my translations were in the Python code and the HTML templates. On a few places I needed some translations in Javascript and did this by pulling this Javascript code inline in the HTML template. For example, for forms I needed: e.target.setCustomValidity('Please fill out this field.'); I ...
Read more