<?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: MDGF93</title>
    <description>The latest articles on Forem by MDGF93 (@mdgf93).</description>
    <link>https://forem.com/mdgf93</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%2F711055%2Fee03a7a0-f04c-479b-af1b-142e4e8f1f2d.jpeg</url>
      <title>Forem: MDGF93</title>
      <link>https://forem.com/mdgf93</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/mdgf93"/>
    <language>en</language>
    <item>
      <title>Writing about Django — #1</title>
      <dc:creator>MDGF93</dc:creator>
      <pubDate>Tue, 03 May 2022 22:37:23 +0000</pubDate>
      <link>https://forem.com/mdgf93/writing-about-django-1-534n</link>
      <guid>https://forem.com/mdgf93/writing-about-django-1-534n</guid>
      <description>&lt;p&gt;Yay for second post ever 🥳(it kinda just took me 2 whole months, but that's k)&lt;/p&gt;

&lt;p&gt;So, we doing &lt;em&gt;&lt;strong&gt;Django&lt;/strong&gt;&lt;/em&gt; now. Why? Cause I like Python more.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6nDICd5s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/2bc4M3A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6nDICd5s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/2bc4M3A.png" alt="Django logo" width="436" height="198"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, what's Django? An easier Spring Boot. That's it. It accomplishes the same stuff Spring does, but, and that's my own opinion, it's far easier to understand what's going on with it.&lt;/p&gt;

&lt;p&gt;So let's start from the beginning, how do we start up a new project using Django? I'm assuming we already have Django properly installed so open your terminal window on your selected directory and type:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;django-admin startproject your_project_name_goes_in_here_okay&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;¹: Note that you can't use dashes (&lt;strong&gt;&lt;em&gt;-&lt;/em&gt;&lt;/strong&gt;) to separate words on your project's name, so just use underscore.&lt;/p&gt;

&lt;p&gt;Once we do this Django will create a folder with our project name and all the necessary files to get your project² up and running.&lt;/p&gt;

&lt;p&gt;²: A project would be something like a website, a project in Django is, usually, made up of many different apps, and an app is an specific function of that website. Think about a MMORPG website, our project would be the website as a whole, and our apps would be something like a forum, the news section, stuff like that.&lt;/p&gt;

&lt;p&gt;It should something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
my_project
├── my_project
│   ├── __init.py__
│   ├── asgi.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
└── manage.py

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Views&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;URLs are responsible for addresses we want to support, to have available on our website/web-apps. In Django, a view represents a &lt;em&gt;function&lt;/em&gt; or a &lt;em&gt;class&lt;/em&gt; that will handle the logic that's executed when you call for a specific URL. This views is going to handle that specific request (&lt;em&gt;GET, POST, DELETE, PUT,...&lt;/em&gt;) and then it'll return a fitting response for that request. A typical views does stuff like: loading and wrangling data, do some business logic and then return a response data, like and HTML code. &lt;/p&gt;

&lt;p&gt;So, let's write our first view:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;First we create a new app:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZkpDoasT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/28mG7b2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZkpDoasT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/28mG7b2.png" alt="Create app" width="496" height="148"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We navigate to new_app &amp;gt; views.py&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Va1Rbvo7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/OwyqcYD.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Va1Rbvo7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/OwyqcYD.png" alt="Create view" width="562" height="178"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So there we go, now we created a &lt;em&gt;view&lt;/em&gt; in our new_app &lt;em&gt;app&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;But now, how do we make it so Django knows that we wish to return this view after getting a request? We gotta wire it up so Django knows which URL should be returning our &lt;code&gt;index(request)&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;We simply create a new python file &lt;code&gt;urls.py&lt;/code&gt; under our new_app folder&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_project
├── my_project
│   ├── __init.py__
│   ├── asgi.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── my_app
│   ├── migrations
│   ├── __init.py__
│   ├── admin.py
│   ├── apps.py
│   ├── models.py
│   ├── urls.py
│   ├── tests.py
│   └── views.py
└── manage.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;³: Note that we have two different &lt;code&gt;urls.py&lt;/code&gt; files one for our app and another for our whole project.&lt;/p&gt;

&lt;p&gt;Inside our newly created app's &lt;code&gt;urls.py&lt;/code&gt; (&lt;em&gt;my_app &amp;gt; urls.py&lt;/em&gt;) we'll tell Django which link will access our view function&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kn_P4bEY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/x10CXs0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kn_P4bEY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/x10CXs0.png" alt="URLs" width="421" height="195"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But now only our app knows that these URLs and views exists, so we should make it so the whole project knows about them as well, so we go inside our project's &lt;code&gt;urls.py&lt;/code&gt; (&lt;em&gt;my_project &amp;gt; urls.py&lt;/em&gt;) and tell Django that we have this whole app thing going on like so:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--irZTZwqx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/560Ewbg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--irZTZwqx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/560Ewbg.png" alt="Other URLs" width="366" height="195"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So if we know start up our server by going to our terminal window and typing:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;py manage.py runserver&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;and head to &lt;code&gt;http://127.0.0.1:8000/my_app/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We should be greeted with a lovely message saying:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hello, world. You're at the new_app index.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And that's a good place to stop for today.&lt;br&gt;
And that's how we create a &lt;strong&gt;view&lt;/strong&gt; inside our app&lt;/p&gt;

</description>
      <category>python</category>
      <category>django</category>
      <category>devjournal</category>
    </item>
    <item>
      <title>Writing about Spring Boot – #1</title>
      <dc:creator>MDGF93</dc:creator>
      <pubDate>Mon, 21 Mar 2022 02:05:38 +0000</pubDate>
      <link>https://forem.com/mdgf93/writing-about-spring-boot-1-22h1</link>
      <guid>https://forem.com/mdgf93/writing-about-spring-boot-1-22h1</guid>
      <description>&lt;p&gt;Hi, if you end up here by some reason keep in my that this is my first blog post &lt;strong&gt;&lt;em&gt;ever&lt;/em&gt;&lt;/strong&gt; and also that I suck at writing, for real.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mMCtYHiw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zsxysubei5b5z6s8mbn6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mMCtYHiw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zsxysubei5b5z6s8mbn6.png" alt="Spring Boot logo" width="436" height="133"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So what's Spring Boot anyways? I don't know for sure to be honest either, so I'm just gonna research for a bit and will be back in a jiff. So, it turns out that Spring Boot is something called a &lt;em&gt;micro framework&lt;/em&gt;, and it's built on top of something called Spring (that's also a framework) used to help build Spring Applications.&lt;/p&gt;

&lt;p&gt;So, enough with introductions, how do I go about building stuff with it? &lt;/p&gt;

&lt;h2&gt;
  
  
  Hello World
&lt;/h2&gt;

&lt;p&gt;So, first go to src &amp;gt; main &amp;gt; java &amp;gt; maindomainfolder &amp;gt; mainApplication.java&lt;/p&gt;

&lt;p&gt;You should see something along these lines:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--X-_QBE-V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/NvcJwd1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--X-_QBE-V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/NvcJwd1.png" alt="Standard mainApplication.java" width="880" height="475"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we run this code you're going to open a new localhost Apache Server (Apache is one of the Spring Framework applications, just like Spring Boot) you'll be most likely be using either port 8080 or 8888. So just go to your browser and type localhost:8080 on the address bar and you'll be greeted with this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dyGHFAtS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/FchWtXs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dyGHFAtS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/FchWtXs.png" alt="Whielabel initial homepage in Spring boot" width="880" height="264"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's good, that means that everything is running a-ok. So, about that Hello World stuff, to do this we need first to create a &lt;strong&gt;Controller Class&lt;/strong&gt;, and well, what is a controller? I'm not sure, but it's something that makes stuff work – So I just looked up what controllers are: they're a Java Class responsible for handling REST API requests, they must contain the following annotation: &lt;code&gt;@RestController&lt;/code&gt; – so we first create a controller and inside that controller we must map a URI to a function, and that function will be the output for that URI. So, we'll have something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IKBE1oWr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f2ccpsfr7ecr5kdz7ska.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IKBE1oWr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f2ccpsfr7ecr5kdz7ska.png" alt="Hello Maria Helena" width="880" height="466"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see we have this thing called a controller and inside the controller we're mapping a URI to an output, in that case the URI is "/test/", so, when we access &lt;code&gt;localhost:8080/test/&lt;/code&gt; we'll be greeted with this lovely page:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8A-ZjO-0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/BhgeTbD.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8A-ZjO-0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/BhgeTbD.png" alt="/test/" width="417" height="96"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And there we have it, that's our &lt;code&gt;hello world&lt;/code&gt;. I guess this will be it for today, hopefully this journal we'll become a bi-weekly habit, I feel like I retain much more information if I start typing it out.&lt;/p&gt;



&lt;center&gt;-- &lt;strong&gt;🅴🅽🅳&lt;/strong&gt; --&lt;/center&gt;

</description>
      <category>springboo</category>
      <category>java</category>
      <category>devjournal</category>
    </item>
    <item>
      <title>Hello, World</title>
      <dc:creator>MDGF93</dc:creator>
      <pubDate>Thu, 23 Sep 2021 13:01:35 +0000</pubDate>
      <link>https://forem.com/mdgf93/hello-world-20df</link>
      <guid>https://forem.com/mdgf93/hello-world-20df</guid>
      <description>&lt;p&gt;Hey, this is just a test post so I can see if I can make my GitHub readme work properly :)&lt;/p&gt;

</description>
      <category>livestreaming</category>
      <category>devrel</category>
      <category>community</category>
      <category>tooling</category>
    </item>
  </channel>
</rss>
