Tldr

TLDR: Generate Django Secret Key

Published on

TLDR: Generate Django Secret Key

Raise your hand if you never versioned the Django’s SECRET_KEY at the beginning of a project and needed to generate a new one before going to production.

This TLDR is a quick reminder of how to generate a secret key locally, without going to some website on the internet to generate it for you.

Django generates a secret key every time that you create a new project, so this function already exists at its code, and you can access it in this way:


TLDR: Write and Read Unicode from files with Python 2 and 3

Published on

TLDR: Write and Read Unicode from files with Python 2 and 3

Chatting with a friend, Mário Sérgio, about problems that happen when you migrate your codebase from Python versions, I came out with the idea of writing this TLDR.

I hope it can help someone that is trying to work with texts that contain Unicode characters that don’t fall back into the ASCII table like other than the roman alphabet and emoji.

On Python 2 there’s no distinction between byte and string. It leads us to eventually not correctly encode/decode the data when we deal with input and output. That kind of mistake can cause runtime errors like that:


TLDR: Python Dev Dependencies on Ubuntu

Published on

TLDR: Python Dev Dependencies on Ubuntu

Some libraries aren’t 100% packaged Python code, some of them are bindings to external libraries. They offer a Python interface so you can call them inside your code. On these cases, we need to install them previously at the system so the python package can work.

When that happens, we get this kind of error:

ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3

To solve errors like that, you need to install the external library, and the system configures everything to you. However, if you work with multiple Python versions managed by pyenv, you have to rebuild all python versions every time that you remember to install a new dependency.


TLDR: Setting mutable objects at Django Model Field default

Published on

TLDR: Setting mutable objects at Django Model Field default

This post it the result of a bug that haunted me for three months until I finally could isolate the error properly, and get to the root of the issue.

One of the core parameters of a Django Model field is the default. It sets the value of the Field when you don’t pass a value to it at the Model instance creation. The default parameter can receive a value or a callable, and callable are functions or any object that implements the __call__ method.


TLDR: How to Publish to PyPI

Published on

TLDR: How to Publish to PyPI

Have you ever asked yourself how to publish your Python package, so you can install it using pip? It is less complex than it seems, and anyone can do it.

The first step is to create an account on the Python Package Index (PyPI) were all Python packages are registered.

After that, you need to create a file called setup.py on the root folder of the Python code that you will publish with the following content, changing the values were is needed:


TLDR: Running commands at multiple hosts with Fabric

Published on

TLDR: Running commands at multiple hosts with Fabric

Recently someones asked me how to perform a connection to a server to run the command df -h using ssh to display the disk usage of the machine. After a quick chat, I discovered that the question was more than just a single check to a server. It was to extend that to multiple servers.

The answer to the question was quick and came with a “click”. How about to document these quick tips at the blog? It can help someone and also help me to remind me how to do something if I need it in the future. With that in mind, I created this series of posts that I kindly baptized as TLDR the abbreviation for Too Long ** D**idn’t Read.