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 automationWerkzeugWheelsWTFormsYouTubeOWASP Zed Attack Proxy (ZAP) security testing
13 January 2020 0
Peter
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 ...
Flask, Babel and Javascript language files
6 January 2020 0
Peter
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 ...
Flask site penetration tests: security headers and the session cookie
27 December 2019 0
Peter
You created a Flask web application, it is running fine and using https. But is it secure enough? Did you do everything to protect your visitors, did you do everything to prevent malicious attacks? A good way to proceed on this is to pentest your site. Penetration testing tools, or pen testing tools, can identifying security weaknesses. They identify vulnerabilities in the web application that can ...
Docker on Debian / Ubuntu not respecting ufw firewall settings exposing ports
9 December 2019 1
Peter
Again another unexpected Docker issue. In a previous post I described why and how you must force Docker to use a subnet, to prevent sudden unexpected changes in the network with consequences like mail no longer working. This post is about Docker not respecting firewall settings, at least when running Debian / Ubuntu and ufw (Uncomplicated Firewall). Docker does not tell you this, and exposes ports, ...
Docker containers suddenly using 192.168.0.0/16 instead of 172.17.0.0/16: services lost
27 November 2019 0
Peter
I have an ISPConfig server with Docker applications. They use the host Postfix mail transfer agent (MTA) to deliver mail to the outside world. Before using the send mail function I have a check if Postfix can be accessed. This works fine. But suddenly mail was not sent. The log file contained error messages like: 2019-11-26 17:31:56,758 ERROR MailMessage - send_mail: self.error_message = sending message, ...
Using Python kwargs (keyword arguments) in Flask url_for() for pagination
24 November 2019 0
Peter
For this website I am using Flask and SQLAlchemy without the Flask-SQLAlchemy extension. I need pagination for several pages. For example the home page holds the list of blogs and it should show a maximum of 12 items per page. It is not that difficult to implement. The home page view function requires a page_number that defaults to 1 if it not specified: @pages_blueprint.route('/', defaults={'page_number': ...
Developing Ubuntu Touch apps with Python using pyOtherSide
18 November 2019 0
Peter
Probably many of you know only two mobile phone operating systems, iOS on Apple phones, and Googles Android on all other phones (some 80%). But there is also Ubuntu Touch (UT) originally developed by Canonical Ltd. and continued by UBports. I write a post about this because I am using UT on a Nexus 5 and wondered how difficult it would be to develop apps for it. When I discovered that you can use Python ...
How to set the timezone when using the Python Alpine Docker image
13 November 2019 0
Peter
While writing an application on my Docker platform I hit an unexpected problem, yes, another one ... This was the first time that I had to show the time on a page of a website running on Docker and it appeared that the time was UTC instead of local time. In the code I was just using the normal Python calls to get the time: import datetime ... now = datetime.datetime.now() hour = now.hour ...
Flask multilanguage processing, switching and the 404 Page Not Found exception
13 November 2019 0
Peter
How to implement Flask multilanguage is explained in the Flask docs, see links below. But this is just a starting point. You need deeper understanding of the process to handle special cases like falling back to a default language, language switching, and the 404 Page Not Found exception. Assumptions In the remainder of this post we are using a language code, 'lang_code', that is available in the ...
ISPConfig: running a Python Flask Docker container as a jailed Shell User
18 October 2019 0
Peter
I run a server with ISPConfig with some 50 sites. The sites are static or PHP. I am developing Python Flask applications now and also want to run them on the ISPConfig server. You can create virtual environments on the ISPConfig server and run your application from here. But some time ago I have chosen to use Docker for development, staging and production. It takes time to set this up ...
Two Flask apps, frontend and admin, on one domain using DispatcherMiddleware
9 October 2019 3
Peter
The Flask application I am writing to run this website has all code in a single 'app'. I already did some reorganizing as I wanted full separation of frontend code and the administration code. Now it it is time for total separation, meaning making the frontend a Flask app and the admin another Flask app while both running in the same domain and both reside in the same project directory. Because we ...
Adding a contact form to a multilanguage page with content from a database
28 September 2019 0
Peter
Update 11 October 2019: I changed the addon-tag from '{% addon: ... %}' to '[[ addon: ... ]]'. The reason is that I wanted to be able to render the page text coming from the database, using render_template_string, and '{% ... %}' conflicts with Jinja2 tags. And yes, I do not want to implement a Jinja2 custom tag. What is difficult about implementing a contact page with a contact form with Flask ...
Adding url_for() links to Jinja templates of a Flask multilanguage website
15 September 2019 0
Peter
Before you read on, you may want to read my previous posts about multilanguage and language fallback, see links below. When I gave myself the assignment to develop and implement a multilanguage Flask website with SQLAlchemy I knew things could get difficult. I did not really took the time to design everything beforehand, I just read a lot about multilanguage on the internet and trusted my experience ...
Multilanguage fallback revisited and a page footer with multilanguage links
14 September 2019 0
Peter
Before you read on, you may want to read my previous post about language fallback, see link below. Here you have an example of the complexity of multilanguage. The link should be shown in the language you are using at the moment ... another time. Life is one long big sequence of problems we are solving all the time. It starts with getting enough oxygen, solved by breathing, maybe second ...
Refining multilanguage: adding language fallback as an option
11 September 2019 0
Peter
In a previous post I described the first version of the multilanguage database used on this website. For every table that has fields that must translated, we add a 'translation' table with these fields. I also implemented language fallback: if an item, like a blog post, does not exist in the selected language then the item of the (system-wide) default language is shown. This works fine but now I want ...
Making DeepL API machine translations a little bit better
31 August 2019 0
Peter
Update: Using reserved words is only working if you keep the words in place. I first substituted them for non-translatable tags but then DeepL does not know what it is doing anymore. Of course nothing compares to a translation by a professional translator. Machine translation is difficult. DeepL tries to improve translations by machine learning but they are still far away from using the proper ...
Reducing page response times of a Flask SQLAlchemy website
29 August 2019 0
Peter
Objects, it is nice to build an application with them but it has one very big disadvantage: it can be very slow because of the extra CPU-cycles and all the extra memory used. The slowdown of course is very much caused by the extra mapper layers and extra data. Should you care about performance? Yes! The admin part of an application does not have to be very fast but the frontend pages, the pages ...
Converting to a multilanguage database
25 August 2019 0
Peter
When I started this project, this website, I kept in mind that it had to support multiple languages. But of course I did not really look into database design because of all the other things I had to learn, add and implement. After a certain moment I could display and select multiple languages but that was for the texts in the code and templates and not for the database content items like blog posts ...
Reorganize, restructure, move to content items, add themes, add more languages
14 August 2019 0
Peter
This post is about editing code, a lot of editing, huge amounts of editing! When you implement much functionality, you notice things that need attention, things that need you to research, how do others do this, what is the plural of certain words, etc. I maintain a todo list and every time I noticed something that needed attention I added it to this list. The list got too big so I decided to stop adding ...
Building a multilanguage Flask website with Flask-Babel
7 August 2019 1
Peter
With a single language there is not really a problem, we just forget about the rest of the world and build our single language Flask application. We start getting a headache when the website must support multiple languages. What exactly is a website supporting multiple languages? How many languages will be supported, and which languages? For English there are for example en-GB and en-US. Which parts ...