<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Django on Humberto Rocha</title><link>https://humberto.io/tags/django/</link><description>Recent content in Django on Humberto Rocha</description><generator>Hugo</generator><language>en</language><lastBuildDate>Sun, 20 Nov 2022 15:29:07 -0500</lastBuildDate><atom:link href="https://humberto.io/tags/django/index.xml" rel="self" type="application/rss+xml"/><item><title>TLDR: Generate Django Secret Key</title><link>https://humberto.io/blog/tldr-generate-django-secret-key/</link><pubDate>Fri, 12 Jul 2019 00:00:00 +0000</pubDate><guid>https://humberto.io/blog/tldr-generate-django-secret-key/</guid><description>&lt;p&gt;Raise your hand if you never versioned the Django&amp;rsquo;s &lt;code&gt;SECRET_KEY&lt;/code&gt; at the beginning of a project and needed to generate a new one before going to production.&lt;/p&gt;
&lt;p&gt;This &lt;strong&gt;TLDR&lt;/strong&gt; 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.&lt;/p&gt;
&lt;p&gt;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:&lt;/p&gt;</description></item><item><title>TLDR: Setting mutable objects at Django Model Field default</title><link>https://humberto.io/blog/tldr-setting-mutable-objects-at-django-model-field-default/</link><pubDate>Wed, 25 Apr 2018 00:00:00 +0000</pubDate><guid>https://humberto.io/blog/tldr-setting-mutable-objects-at-django-model-field-default/</guid><description>&lt;p&gt;This post it the result of a &lt;strong&gt;bug&lt;/strong&gt; that haunted me for three months until I finally could isolate the error properly, and get to the root of the issue.&lt;/p&gt;
&lt;aside class="tip warning"&gt;
 &lt;strong&gt;Disclaimer:&lt;/strong&gt; this information exists at the &lt;a href="https://docs.djangoproject.com/en/2.2/ref/models/fields/#default"&gt;Django&lt;/a&gt; docs, however strengthening the importance of this info is vital to prevent people to spend a lot of time with this kind of bug.
&lt;/aside&gt;

&lt;p&gt;One of the core parameters of a Django &lt;strong&gt;Model field&lt;/strong&gt; is the &lt;strong&gt;default&lt;/strong&gt;. It sets the value of the &lt;strong&gt;Field&lt;/strong&gt; when you don&amp;rsquo;t pass a value to it at the &lt;strong&gt;Model&lt;/strong&gt; instance creation. The default parameter can receive a &lt;strong&gt;value&lt;/strong&gt; or a &lt;strong&gt;callable&lt;/strong&gt;, and callable are functions or any object that implements the &lt;code&gt;__call__&lt;/code&gt; method.&lt;/p&gt;</description></item><item><title>JWT Authentication with Angular and Django</title><link>https://humberto.io/blog/jwt-authentication-with-angular-and-django/</link><pubDate>Sun, 15 Apr 2018 00:00:00 +0000</pubDate><guid>https://humberto.io/blog/jwt-authentication-with-angular-and-django/</guid><description>&lt;p&gt;Almost every system that runs on the internet and stores user data has an authentication layer. With the API architecture becoming popular nowadays, the complexity of the authentication layer also grew.&lt;/p&gt;
&lt;p&gt;This post was made to explain the authentication process between a frontend written in &lt;strong&gt;Angular 6&lt;/strong&gt; and a backend written in &lt;strong&gt;Django 2&lt;/strong&gt; using the architecture proposed on my previous post &lt;a href="https://humberto.io/blog/separating-frontend-from-backend-with-angular-and-django/"&gt;&amp;ldquo;Separating Frontend from Backend with Angular and Django&amp;rdquo;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The repositories with this post code are:&lt;/p&gt;</description></item><item><title>Separating Frontend from Backend with Angular and Django</title><link>https://humberto.io/blog/separating-frontend-from-backend-with-angular-and-django/</link><pubDate>Tue, 13 Feb 2018 00:00:00 +0000</pubDate><guid>https://humberto.io/blog/separating-frontend-from-backend-with-angular-and-django/</guid><description>&lt;p&gt;At web development, things evolve and grow in complexity faster than we can follow. That old way of creating websites where the pages were built only with HTML and if you had to change something you had to go through many pages changing the same thing is something rare nowadays. Now, even to create static websites, we use tools to optimize our work.&lt;/p&gt;
&lt;p&gt;On the last years, we had an increase in javascript frameworks and an excellent evolution on the frontend as a whole. These new technologies have their tools and pipelines that makes harder to a single system to deliver both frontend and backend.&lt;/p&gt;</description></item><item><title>Django Generic ManyToMany Relations</title><link>https://humberto.io/blog/django-generic-manytomany-relations/</link><pubDate>Fri, 29 Apr 2016 00:00:00 +0000</pubDate><guid>https://humberto.io/blog/django-generic-manytomany-relations/</guid><description>&lt;p&gt;Django&amp;rsquo;s official documentation nicely covers its generic relationship functionality when you have to make an &lt;strong&gt;OneToMany&lt;/strong&gt; (one-to-many or &lt;strong&gt;1:N&lt;/strong&gt;) relation, but when you need to implement a generic &lt;strong&gt;ManyToMany&lt;/strong&gt; (many-to-many or &lt;strong&gt;N:N&lt;/strong&gt;) relation, there is not much documentation about it.&lt;/p&gt;
&lt;p&gt;I recently had to implement an &lt;strong&gt;N:N&lt;/strong&gt; with a generic side, and discovered a library called &lt;a href="http://django-gm2m.readthedocs.io/en/stable/index.html"&gt;django-gm2m&lt;/a&gt; that was very useful to me in this task, and I will describe here giving tips on how to make this implementation and how to avoid possible headaches.&lt;/p&gt;</description></item></channel></rss>