Recently I had a problem of memory usage in Django: when I accessed an apparently innocent view I saw the memory usage of my server grow without rest. The problem turned out to be very trivial to solve, but I think the process I used to find the leak is worth a blog post. 😉
Assume that you have a Django project where each user belongs to just one group, say Registered or Admin, but not both.
You want to show a form in your front-end to let Admin users edit the user profiles, where each user profile is made with First name, Last name, Email and the user group.
This task can be accomplished very easily! What you need is a customized ModelForm to add the possibility to edit the user group together with the other fields, and a customized UpdateView to let you set the form initial data for the group field, and to save the changes correctly.
Sometimes it could be useful and elegant to have a Django view responding to more that GET and POST requests, implementing a simple REST interface. In this post I’ll show how you can support PUT and DELETE HTTP requests in Django.
Google Cloud Print (GCP) is a quite useful Google service, allowing you to print in a GCP compliant printer from everywhere and from every device of yours, be it a desktop, a tablet or a smartphone. There are quote a lot of printers out there supporting GCP out of the box, but here I will explain how to turn every Linux supported printer in a fully functional GCP printer. As a bonus you’ll have a cheap Linux based print server in your local network, which is alone a nice thing to have. All this thank to the amazing Raspberry PI ARM GNU/Linux mini PC.
Fast and easy! $ sudo stop mysql $ sudo -umysql mysqld_safe --skip-grant-tables & $ mysql mysql> UPDATE mysql.user SET Password=PASSWORD('newpassword') WHERE User='root'; mysql> FLUSH PRIVILEGES; $ sudo kill `cat /var/run/mysqld/mysqld.pid` $ sudo start mysql Enjoy your new mysql root password!
If you administer at least one Joomla instance you’ll be subject to brute force attacks before or after. Fail2ban is a very nice service written in Python which periodically scans your log files looking for signs of brute force attacks and perform some actions when an attack is discovered. The most common actions is to ban the attacker IP at firewall level and send an email to the server administrator.
Fail2ban comes bundled with filters for many common services (ssh, apache authentication, etc.), but it lacks a built-in Joomla integration. Anyway it’s easy to add a Joomla filter to Fail2ban, here I explain how to do it.
Since some months I’m using Toggl to track my work time, and I find it awesome! Toggl features a very powerful reporting system to have your timesheets filtered in many ways and exported in csv or pdf format, but I did not found the way to have an Excel timesheet as I like it.
Recently a client asked me to investigate the possibility to have a Django application hosted in a Windows environment. I looked around a bit and there are many ways to achieve this goal. I found the “pure Python” approach described here simpler to deploy and configure, yet very powerful and production ready for my needs.
I will explain how to install Python, CherryPy and Django on Windows, and how to configure them to serve a Django application from the CherryPy WSGI server, running as a Windows service.