<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Trey Piepmeier</title>
    <description>The latest articles on Forem by Trey Piepmeier (@battlecat).</description>
    <link>https://forem.com/battlecat</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1977982%2F978f3f2d-9741-43bc-922a-c84c00e4cb7c.jpg</url>
      <title>Forem: Trey Piepmeier</title>
      <link>https://forem.com/battlecat</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/battlecat"/>
    <language>en</language>
    <item>
      <title>Django is for everyone.</title>
      <dc:creator>Trey Piepmeier</dc:creator>
      <pubDate>Wed, 28 Aug 2024 12:31:46 +0000</pubDate>
      <link>https://forem.com/battlecat/django-is-for-everyone-3dkp</link>
      <guid>https://forem.com/battlecat/django-is-for-everyone-3dkp</guid>
      <description>&lt;p&gt;&lt;a href="https://www.flickr.com/photos/philbarbato/3087493595" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F36bgfhy64pt1ydj5iofd.jpg" alt="A stuffed animal green gorilla in a python-suit" width="600" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Django is great even for “small” websites
&lt;/h2&gt;

&lt;p&gt;I think people tend to consider Django either for building old-school, industrial-strength monolith apps or for &lt;a href="https://www.django-rest-framework.org" rel="noopener noreferrer"&gt;APIs&lt;/a&gt; and using something like &lt;a href="https://deletereact.com" rel="noopener noreferrer"&gt;React&lt;/a&gt; for the front-end. I’m here to tell you that plain old Django is a great option even for your personal websites! In my opinion, if you need a database, you should use Django&lt;sup id="fnref1"&gt;1&lt;/sup&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Django?
&lt;/h2&gt;

&lt;p&gt;Django is considered a “batteries-included” framework, and those batteries are awesome. These are the things that keep me using Django over any other framework. &lt;/p&gt;

&lt;h3&gt;
  
  
  The Object-Relational Mapper (ORM)
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/playlist?list=PL-2EBeDYMIbQXKsyNweppuFptuogJe2L-" rel="noopener noreferrer"&gt;The Django ORM&lt;/a&gt; is a huge reason to use the framework. I’m flabbergasted that not all web frameworks include an ORM. Unless you’re a huge fan of writing SQL from scratch, this is the right way to build apps. You define models, you create database migrations from those models (&lt;em&gt;mostly&lt;/em&gt; automatically), run the migrations on your database and you’re good to go! No writing half-assed models plus a series of migrations where you can sort of extrapolate the schema&lt;sup id="fnref2"&gt;2&lt;/sup&gt;. &lt;em&gt;All&lt;/em&gt; the information you need about your data is in your &lt;code&gt;models.py&lt;/code&gt; file and everything flows from that. &lt;/p&gt;

&lt;h3&gt;
  
  
  The Admin
&lt;/h3&gt;

&lt;p&gt;This is the big one. It’s not a CMS; it’s more of a GUI for the ORM. After you define your models you can, with &lt;em&gt;very little&lt;/em&gt; configuration, manage that data without having to write any &lt;a href="https://en.wikipedia.org/wiki/Create,_read,_update_and_delete" rel="noopener noreferrer"&gt;CRUD&lt;/a&gt; code. It’s not the front-end of your application. It’s not a CMS for end-users (probably). It’s a way for administrators to easily make changes to the site.&lt;/p&gt;

&lt;h3&gt;
  
  
  Progressive Enhancement
&lt;/h3&gt;

&lt;p&gt;This is very near and dear to my heart, but most of the rest of our industry seems to have forgotten. Simply put; base-level functionality should be possible even when JavaScript fails. Your app should be able to at least limp along without front-end scripting. Doing that with a SPA is a nightmare. Doing it with a real backend framework plus a tool like &lt;a href="https://htmx.org/" rel="noopener noreferrer"&gt;htmx&lt;/a&gt; or &lt;a href="https://unpoly.com/" rel="noopener noreferrer"&gt;Unpoly&lt;/a&gt; is trivial. You just have to change your perspective from the status quo to common sense.&lt;/p&gt;

&lt;h2&gt;
  
  
  Concepts to keep in mind
&lt;/h2&gt;

&lt;h3&gt;
  
  
  MTV
&lt;/h3&gt;

&lt;p&gt;While traditional application frameworks use the &lt;a href="https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller" rel="noopener noreferrer"&gt;Model, View, Controller design pattern&lt;/a&gt;; Django names their elements a little differently.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Model

&lt;ul&gt;
&lt;li&gt;Ok, this one is the same.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Template

&lt;ul&gt;
&lt;li&gt;This is equivalent to the traditional &lt;em&gt;View&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;View

&lt;ul&gt;
&lt;li&gt;This is mostly equivalent to the traditional &lt;em&gt;Controller&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  Database Migrations
&lt;/h3&gt;

&lt;p&gt;This is a solved problem in Django. It’s really nice! There’s lots more to know about it, and you &lt;em&gt;should&lt;/em&gt; look at the generated migration files before running them, &lt;em&gt;and&lt;/em&gt; there are times when you’ll need to do this stuff more manually, but this is the crux of using it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;./manage.py makemigrations
&lt;span class="c"&gt;# It tells you what it did.&lt;/span&gt;

./manage.py migrate
&lt;span class="c"&gt;# Database updated!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s it! 🎉&lt;/p&gt;

&lt;h2&gt;
  
  
  How to get started
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Blaze.horse
&lt;/h3&gt;

&lt;p&gt;Here’s where I shill for &lt;a href="https://blaze.horse" rel="noopener noreferrer"&gt;my own little project&lt;/a&gt;. The good news for you, solo developer that I imagine is reading this, is that it’s free for non-commercial use. If you end up using it and it helped you build a commercial application, &lt;a href="https://hub.piep.works" rel="noopener noreferrer"&gt;it’s only $100 USD &lt;em&gt;one time&lt;/em&gt;&lt;/a&gt;. C’mon, that’s quite a value!&lt;/p&gt;

&lt;p&gt;Even if you don’t end up using the whole kit, I urge you to look over the techniques I use in &lt;a href="https://github.com/piepworks/blaze-starter" rel="noopener noreferrer"&gt;the code&lt;/a&gt;. That’s hard-won stuff after using Django almost since its beginning. I went through a phase of using it with Docker and Postgres, but I really believe this is &lt;em&gt;the&lt;/em&gt; way for 99% of folks who want to give Django a try. SQLite is amazing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deployment
&lt;/h3&gt;

&lt;p&gt;Unfortunately, this is the main downside of choosing Django over other options targeted at personal websites. With Blaze.horse, I’ve tried to &lt;a href="https://github.com/piepworks/blaze-starter/tree/main/documentation/deployment" rel="noopener noreferrer"&gt;set you up for an easy time&lt;/a&gt;, but it’s still fiddlier than it ought to be. There are some up-and-coming projects that give me hope, such as &lt;a href="https://btn.dev/" rel="noopener noreferrer"&gt;Button&lt;/a&gt; and &lt;a href="https://appliku.com/" rel="noopener noreferrer"&gt;Appliku&lt;/a&gt;, but I’m personally happy with &lt;a href="https://fly.io" rel="noopener noreferrer"&gt;Fly&lt;/a&gt; for now.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next steps
&lt;/h2&gt;

&lt;p&gt;After reading this, I hope you’ll keep Django in mind the next time you need build something. &lt;a href="https://piep.works" rel="noopener noreferrer"&gt;Let me know if I can help!&lt;/a&gt;&lt;/p&gt;




&lt;ol&gt;

&lt;li id="fn1"&gt;
&lt;p&gt;If you need a CMS, you should use &lt;a href="https://getkirby.com" rel="noopener noreferrer"&gt;Kirby&lt;/a&gt;. You &lt;em&gt;certainly&lt;/em&gt; shouldn’t be using a static site generator if you need a CMS. FFS ↩&lt;/p&gt;
&lt;/li&gt;

&lt;li id="fn2"&gt;
&lt;p&gt;Laravel ↩&lt;/p&gt;
&lt;/li&gt;

&lt;/ol&gt;

</description>
      <category>django</category>
      <category>progressiveenhancement</category>
      <category>python</category>
    </item>
  </channel>
</rss>
