Recent
- Hiding database UUID primary keys of your web application
- Don't Repeat Yourself (DRY) with Jinja2
- SQLAlchemy, PostgreSQL, maximum number of rows per user
- Show the values in SQLAlchemy dynamic filters
- Secure data transfer with Public Key encryption and pyNaCl
- rqlite: a high-availability and distributed SQLite alternative
Most viewed
- Using Python's pyOpenSSL to verify SSL certificates downloaded from a host
- Using UUIDs instead of Integer Autoincrement Primary Keys with SQLAlchemy and MariaDb
- Connect to a service on a Docker host from a Docker container
- Using PyInstaller and Cython to create a Python executable
- SQLAlchemy: Using Cascade Deletes to delete related objects
- Flask RESTful API request parameter validation with Marshmallow schemas
Tags
AiohttpAJAXAlembicAlpineAPIApplication settingsAsyncBabelBeautifulSoupBootstrapCachingCaptchaCeleryColorsCompileCronCryptographyCSRF protectionCythonDecoratorDeep LearningDeepLDispatcherMiddleWareDistributionDNSDockerDocker SwarmDocker-composeEmailExceptionsFastAPIFlaskGunicornIconsIMAPInternetISPConfigJavascriptJinja2KubernetesLog fileLoggingMachine LearningMariaDBMessage brokerMultilanguageMultiprocessingPentestingPikaPostfixPostgreSQLProfilingPyInstallerpyOpenSSLPytestRabbitMQRedisrqliteScrapingSecuritySecurity testingSeleniumSlackSQLAlchemyTestingThreadsTimezoneToastsUbuntu TouchUUIDWeb automationWerkzeugWheelsWTFormsYouTubeRunning multiple (Flask) websites with a single Docker setup
30 September 2020 0
Peter
I developed one Flask website on Docker but after some time when my code became more stable I wanted to use the same setup for other websites. For one website I made a copy because it had to work yesterday. But what I really wanted was to share all the code, and some of templates. Of course every website has its own static directory, logging directory, templates, etc. The main reason for sharing is ...
Testing the Docker .dockerignore file patterns
22 September 2020 0
Peter
This is a short post about something I wanted to do a long time ago and for which I finally found some time. It was not really a case of TL;DR (Too Long; didn't read), but more something like TLT;DR (Too Little Time; didn't read). As you probably know, the Docker .dockerignore file is used to prevent certain files and directories ending up in your Docker image. The Docker .dockerignore file is used ...
Using Python to get Postfix sent status for messages with a message-id
20 August 2020 0
Peter
The problem: I have a website that sends emails. The emails (meta) are stored in a database before sending to the Postfix MTA. Every email the website sends has a unique message-id, something like 159766775024.77.9154479190021576437@peterspython.com. I want to check if the emails are actually sent and add this information to the email (meta) database records. Postfix has statuses like: status=bounced ...
Functional testing a multilanguage Flask website with Pytest
25 July 2020 1
Peter
Testing is hard work. It is totally different from creating or modifying functionality. I know, I also developed computer hardware, integrated circuits, hardware test systems. I wrote tests for CPUs, computer products, developed test systems. With hardware you cannot make mistakes. Mistakes may be the end of your company. Welcome to the wonderful world of software testing With software many things ...
IMAPClient and fetching body parts
26 June 2020 0
Peter
I decided to temporarily shift focus from developing the software for my CMS / Blog to a smaller project. Main reason is that I hoped to learn new things about Python that are useful. I always wanted to have my own IMAP client software. Maybe my choice was also heavily influenced by some annoyance about the IMAP client Dekko2 for Ubuntu Touch, the OS of my mobile phone. I know that I should be happy ...
Must-read: Internet advertising is a company town by Trevor Jim
17 June 2020 0
Peter
When searching for something on the internet you sometimes bump into an article that perfectly describes what you are already telling friends, colleagues for many years. Whether you are a publisher, a software developer, an advertising company, this Trevor Jim's article is a must-read. Here are the first lines: Internet advertising is a company town February 28, 2017 If you’ve watched a lot ...
Create your own Python custom exception classes tailored to your application
17 June 2020 0
Peter
Using exceptions in Python looks easy but it is not. Probably you should study exceptions and exception handling before writing any Python code but TL;DR. There are examples on the internet, unfortunately most are very trivial. Anyway, I researched this and came up with some code I thought I share with you. Leave a comment if you have suggestions. What is an error and what is an exception, what is ...
Using icons on your Flask website and reducing 'First Contentful Paint'
29 May 2020 0
Peter
There are many types of vector icons. In this post I only look at SVG-icons, and limit myself to navigation icons, sometimes also called interface icons. These icons not only look nice on websites, they also color and scale like fonts. And they are very functional. Imagine a button with the text ' Edit' in it. Replace this text with a pencil-icon and you get more space on the page while it still is ...
Sharing models, classes, Blueprints and templates between apps with Flask DispatcherMiddleWare
12 May 2020 0
Peter
This site is running Flask. It uses DispatcherMiddleWare to run the frontend app and the admin app. The Flask documents state that the Flask applications in this case are entirely isolated from each other. That is true but often there is a lot of code we want to share between these apps. Things we want to share Both apps use the same database meaning we want to share the models.py file. Then we ...
Converting a SQLAlchemy MariaDb / MySQL database with Integer Primary Keys to UUID Primary Keys for a Flask website
26 April 2020 0
Peter
This website uses Flask, (plain) SQLAlchemy with Alembic for migrations and MariaDb. If you do not use these, this post probably is not what you are looking for. In a previous post I wrote why many websites should use UUID Primary Keys instead of Integer Primary Keys. Even if you have a high performance website then probably only few tables are responsible for this performance. High performance websites ...
Blacklisting IP addresses on your Flask website running on Linux
16 April 2020 0
Peter
You have a website and it works fine. But you notice that certain visitors are trying to mess with your forms. They come from specific IP addresses. Then there are also bots that are scanning your site. Some are necessary but others should stay away. Don't you hate this? I do. In the past I once wrote a module that returned a not so nice response very slowly, byte-by-byte, slowing down their systems. ...
Using UUIDs instead of Integer Autoincrement Primary Keys with SQLAlchemy and MariaDb
9 April 2020 1
Peter
We all know the Integer Autoincrement Primary Key. Works great, much software is doing it this way. It is fast. But it also has limitations. An alternative for the Integer Autoincrement Primary Key is the UUID (Universally Unique IDentifier) Primary Key. A UUID is a 128-bit number. It can be represented by a string, for example: 05390f2b-48e8-45c7-8ae4-08272dc69122 or a hex string (the same as above ...
Eliminate repetition and improve maintenance by creating a Flask view class
24 March 2020 0
Peter
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 ...
Do not hesitate to reinvent the wheel if you want your software with open source components to live longer
10 March 2020 0
Peter
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 ...
Flask, WTForms and AJAX: CSRF protection, before_request and multilanguage
29 February 2020 1
Peter
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, ...
Flask with multiple forms on a page posted using AJAX and returning a rendered form result
22 February 2020 0
Peter
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 ...
A textarea with a character counter widget for Flask, WTForms and Bootstrap
15 February 2020 1
Peter
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 ...
Threaded comments using Common Table Expressions (CTE) for a MySQL Flask blog or CMS
8 February 2020 86
Peter
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 ...
The mysterious Flask Application Context, my questions and answers
30 January 2020 0
Peter
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 ...
WTForms image picker widget for Flask with Bootstrap 4 without extra Javascript and CSS
24 January 2020 0
Peter
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 ...