<?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>DEV Community: Akolade</title>
    <description>The latest articles on DEV Community by Akolade (@akolade).</description>
    <link>https://dev.to/akolade</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%2F939471%2F8896e986-7076-43ff-affb-aae84f38d93a.jpeg</url>
      <title>DEV Community: Akolade</title>
      <link>https://dev.to/akolade</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/akolade"/>
    <language>en</language>
    <item>
      <title>Initializing an Array in C#</title>
      <dc:creator>Akolade</dc:creator>
      <pubDate>Tue, 14 May 2024 08:04:17 +0000</pubDate>
      <link>https://dev.to/akolade/initializing-an-array-in-c-32h2</link>
      <guid>https://dev.to/akolade/initializing-an-array-in-c-32h2</guid>
      <description>&lt;p&gt;C# is pretty interesting to write and it is so so fascinating too&lt;/p&gt;

&lt;p&gt;There are different ways to initialize an array in C#, stick to the end, I will show you different ways to go about it.  The best approach will depend on a lot of factors, most especially preference(in my opinion).&lt;/p&gt;

&lt;p&gt;Now let's dive in..... &lt;br&gt;
While there have been latest changes in the last upgrade to C# which is C# 12, I would go all the way back to how it started, well maybe not all the way back. The aim here is to show you all the possible syntaxes to initialize array in C#.&lt;/p&gt;

&lt;p&gt;Below is the list of possible array declarations and initializations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string[] array = new string[2]; 
string[] array = new string[] { "A", "B" };
string[] array = { "A" , "B" }; 
string[] array = new[] { "A", "B" }; 
string[] array = ["A", "B"]; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;let's explain each of them&lt;/p&gt;

&lt;p&gt;&lt;code&gt;string[] array = new string[2];&lt;/code&gt;&lt;br&gt;
This syntax creates a new array of strings that has a length of 2. It is like making an box with space for just two words in it, but we haven't put any words in  it yet.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;string[] array = new string[] { "A", "B" };&lt;/code&gt;&lt;br&gt;
This syntax creates a new array of strings with an explicit initialization. The array is already filled with two elements: "A" and "B". It's like making a box and immediately putting the two words inside it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;string[] array = { "A" , "B" };&lt;/code&gt;&lt;br&gt;
This is a shorter way of creating a new array of strings, it just only omits  &lt;code&gt;new string[]&lt;/code&gt;.but is does the same as the example above. it is like a quicker route to get to the same destination.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;string[] array = new[] { "A", "B" };&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is similar to the second example but it uses the new[] syntax. This syntax allows the compiler to infer the type of the array elements based on the initializer values. Since the initializer values are strings, the array will be of type &lt;code&gt;string[]&lt;/code&gt;. This is like telling the computer to figure out what you are putting in the box &lt;/p&gt;

&lt;p&gt;&lt;code&gt;string[] array = ["A", "B"];&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is the newest way to initialize an array in C# 12, simple and straightforward. It's also similar to the way arrays are initialized in Python and JavaScript. This makes it easier for developers familiar with those languages to work with arrays in C#.&lt;/p&gt;

&lt;p&gt;Starting from C# 3 and above, there is a shorter way to write the first two and fourth declarations. You can write them 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;var array = new string[2];
var array = new string[] { "A", "B" };
var array = new[] { "A", "B" };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is possible because the information on the right side of the assignment is enough to infer the proper type of the array. This makes the code simpler and more concise.&lt;/p&gt;

&lt;p&gt;To wrap this up, it is worthy to note that there are other ways to declare or initialize an array in C#, but we will stick to this methods. These methods cover the most common and straightforward approaches to working with arrays in C# &lt;/p&gt;

&lt;p&gt;Thank you for reading &lt;/p&gt;

&lt;p&gt;You can check me on &lt;a href="https://linkedin.com/in/emmakolade"&gt;LinkedIN&lt;/a&gt; &lt;/p&gt;

</description>
      <category>csharp</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Expanding My Skill Set: A Journey into NodeJS/ExpressJS</title>
      <dc:creator>Akolade</dc:creator>
      <pubDate>Tue, 11 Apr 2023 13:37:00 +0000</pubDate>
      <link>https://dev.to/akolade/expanding-my-skill-set-a-journey-into-nodejsexpressjs-15o3</link>
      <guid>https://dev.to/akolade/expanding-my-skill-set-a-journey-into-nodejsexpressjs-15o3</guid>
      <description>&lt;p&gt;In my quest to become a well rounded backend developer, I recently delved into NodeJS\ExpressJs.&lt;/p&gt;

&lt;p&gt;Coming from a background of writing Django, I noticed some similarities between the two frameworks, albeit with some notable differences. With ExpressJS for example, you must handle the middlewares and controllers directly. Middleware is the fundamental concept and a core part of the framework's design and sits in the middle of the request/response cycle.&lt;/p&gt;

&lt;p&gt;In ExpressJS middleware functions can be used to perform various tasks such as parsing incoming data, authentication, error handling and logging. Middleware is also written as a function that takes three parameters: &lt;code&gt;request&lt;/code&gt;, &lt;code&gt;response&lt;/code&gt; and &lt;code&gt;next&lt;/code&gt;. The Middleware functions can either modify the &lt;code&gt;request&lt;/code&gt; and &lt;code&gt;response&lt;/code&gt; object or terminate the request/response cycle by sending a response or invoking &lt;code&gt;next&lt;/code&gt; to pass control to the next middleware&lt;/p&gt;

&lt;p&gt;But in Django, middleware is an optional feature, I mean you don't need to handle it yourself. It provides a way to process requests and responses globally across all views it sits between the web server and the views functions. The Middleware can also be used for authentication, session management, and caching.&lt;/p&gt;

&lt;p&gt;Django automatically handles the order in which middleware is applied to the request/response chain based on the order in which they are defined in the MIDDLEWARE setting.&lt;/p&gt;

&lt;p&gt;Just know that middleware in Django and ExpressJs serve similar purposes but are handled differently.&lt;/p&gt;

&lt;p&gt;After a few weeks of intensively learning NodeJS/ExpressJS, I have come to appreciate the ease and efficiency of Django. Nonetheless, I built a small app using ExpressJS and, although I am not entirely satisfied with the outcome, I am determined to continue honing my skills in this area.&lt;/p&gt;

&lt;p&gt;In the meantime, you can explore a microservice I recently designed with Django REST Framework. The microservice boasts of a comprehensive authentication system that includes user registration and verification via OTP, as well as OAuth2 integration for social login. I have also implemented logging and monitoring features to ensure optimal performance.&lt;/p&gt;

&lt;p&gt;You can check the code &lt;a href="https://github.com/emmakolade/authentication-microservice"&gt;here&lt;/a&gt;, although it is not yet hosted due to ongoing documentation efforts. However, feel free to clone the repository and explore its features.&lt;/p&gt;

&lt;p&gt;Thank you for reading through. you can follow me on &lt;a href="https://twitter.com/akoladesoft"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>express</category>
      <category>node</category>
      <category>django</category>
    </item>
    <item>
      <title>Django MVT: An Introduction to the Model-View-Template Architecture of a Django App</title>
      <dc:creator>Akolade</dc:creator>
      <pubDate>Mon, 13 Feb 2023 11:40:41 +0000</pubDate>
      <link>https://dev.to/akolade/django-mvt-an-introduction-to-the-model-view-template-architecture-of-a-django-app-23b9</link>
      <guid>https://dev.to/akolade/django-mvt-an-introduction-to-the-model-view-template-architecture-of-a-django-app-23b9</guid>
      <description>&lt;p&gt;MVT/ MTV is an essential concept in Django which is very similar to MVC as used on other frameworks. MVT in Django is a design pattern used to organize components of a Web App.&lt;/p&gt;

&lt;p&gt;MVT architecture consists of three components- Model, View, and Template. These components are very important because they work together to handle the Logic, Data and Presentation of our web application.&lt;/p&gt;

&lt;p&gt;Now let us break it down and explore each component in detail.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbiaev16u5xlyktkyiyrb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbiaev16u5xlyktkyiyrb.png" alt="MVT structure of a Django App" width="800" height="302"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When a User makes a request to fetch a web page, we know that the three most important thing on a web page is the data which is coming from the database, the layout designed with HTML CSS and JS and the Logic.&lt;br&gt;&lt;br&gt;
The User request goes to the web application Django framework then to the URLs the navigation will be sent to the views where the logic is written. Then this view will use the model object and template. the data that needs to be sent will be decided by the view.&lt;/p&gt;

&lt;p&gt;It is important to separate these 3 from each other and this practice is known as the &lt;strong&gt;Separation of Concerns.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Model&lt;/strong&gt;: The model is responsible for managing the data and this can be linked with the models in our app. Model is simply a database table that defines a Python class and extends the Django Models class. In short, the model is used to store and retrieve data from the database. You can read my article on models &lt;a href="https://dev.to/akolade/models-in-django-1kli"&gt;&lt;strong&gt;here&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;View&lt;/strong&gt;: If a user sends a request, Django will check if there is a view for this request and execute accordingly but if there is no view, no response will be returned.&lt;br&gt;&lt;br&gt;
The view is where we write all the logic for our web app and the view fetches the data stored by the Model and renders a template.&lt;br&gt;&lt;br&gt;
To learn more about views, check my previous article &lt;a href="https://akolade.hashnode.dev/writing-views-in-django" rel="noopener noreferrer"&gt;&lt;strong&gt;here&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Template&lt;/strong&gt;: Template is simply the frontend component of our Web App. In order to generate HTML dynamically Django uses DTL- Django template language, with DTL we would be able to display data dynamically.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let's compare MTV to MVC in other languages
&lt;/h3&gt;

&lt;p&gt;Now we know that Django MVT architecture is similar to the Model-View-Controller (MVC) design pattern used in other languages. Well, there are some key differences.&lt;/p&gt;

&lt;p&gt;the Controller in MVC acts as the intermediary between the Model and View. The Controller processes user requests, updates the models and selects the right view to render.&lt;/p&gt;

&lt;p&gt;But this is way different in Django, the View does similar work with the Controller but it is safe to say that the View is not the Controller because in other languages/frameworks, the controller has to be configured but in Django, this has already been handled.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;The Separation of Concerns in Django MVT makes it easier to makes it very easy to maintain and change the look of our web app, the template can be updated without affecting the View or Model.&lt;/p&gt;

&lt;p&gt;Django MVT also allows or promotes the DRY(Don't Repeat Yourself) concept.&lt;/p&gt;

&lt;p&gt;Note this: Regardless of the differences and similarities between MVT and MVC, they are both effective ways to structure the code and components of a web app.&lt;/p&gt;

&lt;p&gt;Whether you are a beginner or a seasoned developer, understanding MVT is essential to building apps in Django.&lt;/p&gt;

&lt;p&gt;Thank you for reading through. If you like this article, you can give me a follow on &lt;a href="https://twitter.com/akoladesoft" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;HAPPY CODING....&lt;/p&gt;

</description>
      <category>digital</category>
      <category>ai</category>
      <category>marketing</category>
      <category>socialmedia</category>
    </item>
    <item>
      <title>Pipenv: Why you should use it as a Python Developer</title>
      <dc:creator>Akolade</dc:creator>
      <pubDate>Wed, 01 Feb 2023 12:43:29 +0000</pubDate>
      <link>https://dev.to/akolade/pipenv-why-you-should-use-it-as-a-python-developer-518d</link>
      <guid>https://dev.to/akolade/pipenv-why-you-should-use-it-as-a-python-developer-518d</guid>
      <description>&lt;p&gt;Pipenv is a tool that aims to bring the best of all packaging worlds to the Python world. It harnesses Pipfile, pip, and virtualenv into one single command. It automatically creates and manages a virtual environment for your projects, as well as adds/removes packages from your Pipfile as you install/uninstall packages.&lt;/p&gt;

&lt;p&gt;Before diving deep, let's look at some of the problems Pipenv tends to solve&lt;/p&gt;

&lt;h3&gt;
  
  
  Problems Pipenv Solves
&lt;/h3&gt;

&lt;p&gt;Pipenv solves the problems of dependency management in Python projects by providing a unified and automated approach to handling dependencies, creating virtual environments, and resolving dependencies. It eliminates the need for manual dependency pinning by locking the dependencies of a project in a &lt;strong&gt;Pipfile.lock&lt;/strong&gt;, ensuring reproducibility and deterministic builds. Unlike requirements.txt, Pipenv does not rely on manual updates for sub-dependencies, as it automatically resolves dependencies and keeps them up-to-date.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dependencies and Virtual Environment Management:&lt;/strong&gt; Pipenv automatically manages the dependencies of your projects, ensuring that the packages your project needs to run are always installed and up-to-date. Pipenv automatically creates a virtual environment for each project, making it easier to isolate projects from one another and manage their dependencies.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Simplifies Package Installation:&lt;/strong&gt; Another issue that Pipenv addresses are the process of installing packages. With traditional methods, such as using a requirements.txt file, the process of installing packages can be complicated and time-consuming. Pipenv simplifies this process by allowing developers to specify the packages required for a project in a Pipfile, which can then be installed with a single command. Furthermore, Pipenv automatically resolves dependencies, making sure that the correct version of each package is installed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reproducibility:&lt;/strong&gt; Pipenv also ensures reproducibility by locking the dependencies of a project in a &lt;strong&gt;Pipfile.lock.&lt;/strong&gt; This makes it possible to easily reproduce a project on another machine. In contrast, when using a requirements.txt file, the dependencies are not locked and it can be difficult to ensure that the same environment is replicated on different machines.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The use of a &lt;strong&gt;requirements.txt&lt;/strong&gt; file can lead to a number of problems, such as the fact that it does not specify the version of a required package to be used. This can result in the latest version of a package being installed, even if it is not backward compatible with the version used during development, causing the application to break in production. Additionally, even if the version of a package is pinned, it is possible that its sub-dependencies will not be pinned, resulting in the latest version being installed and causing issues.&lt;/p&gt;

&lt;p&gt;To address this issue, some developers use the &lt;strong&gt;pip freeze&lt;/strong&gt; command to freeze the exact versions of all packages, including sub-dependencies and include them in a requirements.txt file. However, this method can lead to a new set of problems, as the developer becomes responsible for keeping all packages up-to-date, including sub-dependencies. This can be time-consuming and difficult to manage, especially if a security issue is discovered in a package that requires an immediate update.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pipenv Installation
&lt;/h3&gt;

&lt;p&gt;To install Pipenv, run the following command in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;pipenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run this next command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pipenv shell
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will automatically activate and create a virtual environment.&lt;/p&gt;

&lt;p&gt;Then you should see something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;Creating a virtualenv for this project...
Pipfile:(the directory of your project)
.....
.....
Successfully created virtual environment!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can install our packages with pipenv, and note that if you need to be precise about the version, you need to mention it. for instance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pipenv &lt;span class="nb"&gt;install &lt;/span&gt;&lt;span class="nv"&gt;django&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;4.1.5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you should also see something like this in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;Installing django==4.1.5...
Pipfile.lock not found, creating...
Locking [packages] dependencies...
Locking [dev-packages] dependencies...
Updated Pipfile.lock (c5aae75378f71e86f154c89ed111b8e652646df5f3a7e3d9df5fb1b2b1ba2d88)!
Installing dependencies from Pipfile.lock (ba2d88)...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you check your project directory, you will notice two files already created, a Pipfile and a Pipfile.lock.&lt;/p&gt;

&lt;p&gt;Let's install another package before we continue.&lt;/p&gt;

&lt;p&gt;Assuming you want to run some tests on your application with pytest but are aware that pytest is not required in production, we can signal that this dependence is exclusively for development by using —dev.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
pipenv &lt;span class="nb"&gt;install &lt;/span&gt;pytest &lt;span class="nt"&gt;--dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This argument --dev will put the dependency in &lt;code&gt;[dev-packages]&lt;/code&gt; a special section in the Pipfile.&lt;/p&gt;

&lt;p&gt;We have finally installed all our dependencies and we have built our app. everything is working in development and ready for deployment, right? Before deploying, we must lock our environment to ensure that it remains consistent in production.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;pipenv&lt;/span&gt; &lt;span class="n"&gt;lock&lt;/span&gt;
&lt;span class="c1"&gt;# this command will update the Pipfile.lock. you dont need to manaually edit it since it its not a requirements.txt file.
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;once Pipfile.lock is set, then run this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pipenv &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--ignore-pipfile&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The command installs the most recent successful environment recorded. It also ignores the &lt;strong&gt;Pipfile&lt;/strong&gt; and installs what is in the &lt;strong&gt;Pipfile.lock&lt;/strong&gt; alone.&lt;/p&gt;

&lt;p&gt;If another developer wants to contribute to your code, they just simply need to run this command below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;pipenv&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;dev&lt;/span&gt;
&lt;span class="c1"&gt;# it will install all the dependencies needed for development
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Following this process will solve the problems we have previously discussed. and this will ensure your dependencies both in development and production environments are the same.&lt;/p&gt;

&lt;p&gt;Now Let's Move on...&lt;/p&gt;

&lt;h2&gt;
  
  
  Pifile and Pipfile.lock
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Pipfile:&lt;/strong&gt; The Pipfile is a file used by Pipenv to manage dependencies for a Python project. It is similar to a requirements.txt file but with added features and a different format which is more human-readable. The Pipfile is used to specify the packages that are required for a project to run, as well as the versions of those packages.&lt;/p&gt;

&lt;p&gt;The Pipfile has several sections:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;[source]&lt;/code&gt;: This section lists the sources from which packages can be installed. By default, packages are installed from the Python Package Index (PyPI), but additional sources can be added to this section.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;[packages]&lt;/code&gt;: This section lists all the packages that are required for the project to run, including their versions. The syntax is similar to pip's requirements.txt file, with the package name followed by its version.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;[dev-packages]&lt;/code&gt;: This section lists the packages that are required for development purposes, such as testing frameworks or linting tools. These packages are not needed to run the project but are necessary for development.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;[requires]&lt;/code&gt;: for other requirements like the specific Python version.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight apache"&gt;&lt;code&gt;&lt;span class="err"&gt;[[&lt;/span&gt;source]]
&lt;span class="nc"&gt;url&lt;/span&gt; = "https://pypi.org/simple"
verify_ssl = true
&lt;span class="nc"&gt;name&lt;/span&gt; = "pypi"

&lt;span class="err"&gt;[&lt;/span&gt;packages]
django = "==4.1.5"

&lt;span class="err"&gt;[&lt;/span&gt;dev-packages]
pytest = "*"

&lt;span class="err"&gt;[&lt;/span&gt;requires]
python_version = "3.10"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Pipfile is an important part of Pipenv, as it allows developers to specify the packages that are required for a project to run. Specifying the versions of the packages helps to ensure that everyone working on the project is using the same dependencies.&lt;/p&gt;

&lt;p&gt;The Pipfile makes it easier to share projects and collaborate with others, as it provides a clear list of the dependencies that are required.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Pipfile.lock:&lt;/strong&gt; The pipfile.lock is a file generated by Pipenv that is used to ensure that everyone working on a project has the same dependencies and the same versions of those dependencies.&lt;/p&gt;

&lt;p&gt;The pipfile.lock file is generated based on the information in the Pipfile and contains a complete and accurate record of the packages and their versions that are required for the project to run.&lt;/p&gt;

&lt;p&gt;This information is used by Pipenv to ensure that the correct packages and versions are installed and used when running the project. If a package or its version is changed in the Pipfile, the pipfile.lock file will be updated to reflect those changes.&lt;/p&gt;

&lt;p&gt;The pipfile.lock file is also used to secure the project against vulnerable packages. Pipenv checks the packages listed in the pipfile.lock file against a database of known vulnerabilities, and will alert the developer if any vulnerable packages are detected. This helps to ensure that the project is secure and free from known vulnerabilities.&lt;/p&gt;

&lt;p&gt;The Pipfile.lock looks like this and it uses JSON as it syntax&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"_meta"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"hash"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"sha256"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0401892dedcc2ab095249867cfacc9804fcb29bf6ecfa3423caa2a51e5599e12"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"pipfile-spec"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"requires"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"python_version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"3.10"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"sources"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"pypi"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://pypi.org/simple"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"verify_ssl"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"django"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"hashes"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"sha256:4b214a05fe4c99476e99e2445c8b978c8369c18d4dea8e22ec412862715ad763"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"sha256:ff56ebd7ead0fd5dbe06fe157b0024a7aaea2e0593bb3785fb594cf94dad58ef"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"index"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"pypi"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"==4.1.5"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="err"&gt;.....&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To simply uninstall a package, just run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pipenv uninstall django 
or 
pipenv uninstall &lt;span class="nt"&gt;--all&lt;/span&gt; &lt;span class="c"&gt;# wipes all packages&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How to Convert requirements.txt to Pipfile: To convert a requirements.txt file to a Pipfile, run the following command in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;pipenv&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="n"&gt;requirements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;txt&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Pip and Pipenv - Diffrences
&lt;/h3&gt;

&lt;p&gt;Pip and Pipenv are both package management tools for Python, but they have different purposes.&lt;/p&gt;

&lt;p&gt;Pip is a simple package manager that is used to install and manage Python packages. It's a standard tool that has been included with Python since version 2.7.&lt;/p&gt;

&lt;p&gt;Pipenv, on the other hand, is a more advanced package management tool that aims to bring the best of both pip and virtualenv into one tool. Pipenv provides a more user-friendly interface for managing packages and dependencies, and it automatically creates and manages virtual environments, making it easier to maintain a clean and organized Python environment.&lt;/p&gt;

&lt;p&gt;Pipenv offers a more comprehensive solution for Python package management, but it can be overkill for simple projects, whereas Pip is a more straightforward tool for managing packages.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Should I Use Pipenv and is it worth it?
&lt;/h3&gt;

&lt;p&gt;Using Pipenv is worth considering if you want a more organized and efficient way of managing your Python packages and dependencies.&lt;/p&gt;

&lt;p&gt;With Pipenv, you can create virtual environments for your projects, ensuring that each project has its own set of packages and dependencies without interfering with other projects. This makes it easier to maintain a clean and organized environment, as well as to manage conflicts between dependencies.&lt;/p&gt;

&lt;p&gt;Pipenv provides a user-friendly interface for managing packages and generates a "Pipfile" that serves as a record of all required packages and versions, making it easier to share and reproduce the environment for a project.&lt;/p&gt;

&lt;p&gt;These features make Pipenv a good choice for larger, more complex projects that have multiple dependencies, where it can be difficult to manage packages and dependencies manually.&lt;/p&gt;

&lt;p&gt;Pipenv is a valuable tool for Python developers who want to streamline their workflow and ensure that their projects are well-organized and reproducible.&lt;/p&gt;

&lt;p&gt;Wow you made it here.. I hope you enjoyed the article and that it was informative enough to assist you with your endeavors. Thank you for reading and Happy Coding&lt;/p&gt;

&lt;p&gt;You can follow me on Twitter &lt;a href="https://twitter.com/akoladesoft"&gt;here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>webdev</category>
      <category>django</category>
    </item>
    <item>
      <title>Database: Types, Configuration and Migration</title>
      <dc:creator>Akolade</dc:creator>
      <pubDate>Thu, 26 Jan 2023 11:28:35 +0000</pubDate>
      <link>https://dev.to/akolade/database-types-configuration-and-migration-4f4d</link>
      <guid>https://dev.to/akolade/database-types-configuration-and-migration-4f4d</guid>
      <description>&lt;p&gt;Django comes with its own default database SQLite, which is a lightweight and simple relational database management system.&lt;/p&gt;

&lt;p&gt;While SQLite is a good choice for development and testing, it may not be suitable for production environments due to its limitations such as poor performance, limited concurrency, lack of scalability, limited features, lack of built-in tools for maintenance and lack of built-in security features.&lt;/p&gt;

&lt;p&gt;If you're planning to deploy a Django application in production, you should consider using a more robust and scalable database management system like PostgreSQL or MySQL.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Select A Database
&lt;/h2&gt;

&lt;p&gt;The decision of whether to use a &lt;strong&gt;SQL or NoSQL&lt;/strong&gt; database with Django depends on the specific requirements of your project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SQL&lt;/strong&gt; databases, such as PostgreSQL or MySQL, are well-suited for projects requiring high data integrity and consistency. They provide a structured way of storing and querying data and are well-integrated with Django's ORM (Object-Relational Mapping) system, making it easy to create, query, and modify data using Python classes and objects. SQL databases are also good for projects that have a lot of relationships between data and need to be able to perform complex JOIN operations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NoSQL&lt;/strong&gt; databases, such as MongoDB, are well-suited for projects that handle a lot of unstructured data and require horizontal scalability. They don't have the same level of data integrity and consistency as SQL databases, but they can handle a large amount of data and are designed to scale horizontally. NoSQL databases are also a good fit for projects that need to store and retrieve large amounts of unstructured data, like JSON documents.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It's important to note that Django doesn't officially support NoSQL Databases but they can be integrated using a third-party library.&lt;/strong&gt; Read more &lt;a href="https://docs.djangoproject.com/en/4.1/faq/models/#:~:text=Does%20Django%20support%20NoSQL%20databases,allow%20NoSQL%20functionality%20in%20Django" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Let's configure a Database in our Django settings
&lt;/h3&gt;

&lt;p&gt;I will be using Postgres for this. you can as well check out how to configure a database using MySQL&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;1. Install and configure Postgres.&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Download Postgres &lt;a href="https://www.postgresql.org/download/" rel="noopener noreferrer"&gt;here&lt;/a&gt; for your operating system.&lt;/p&gt;

&lt;p&gt;Install it. Then start your Postgres server.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;2. Install dependencies or database adapter&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;In your environment, install psycopg2: &lt;code&gt;pip install psycopg2&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;we need to now tell Django that we have changed our database.&lt;/p&gt;

&lt;p&gt;You know Django comes with a default configuration for the SQLite database, we need to override that configuration&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;DATABASES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;default&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;ENGINE&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;django.db.backends.sqlite3&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;NAME&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;BASE_DIR&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;db.sqlite3&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For Postgres configuration, the following variables are required.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;DB name&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;DB user&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Password of the User&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Host and Port&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Engine&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;DATABASES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;default&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;ENGINE&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;django.db.backends.postgresql&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;NAME&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;blog&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;USER&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;postgres&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;PASSWORD&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;123456789&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;HOST&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;localhost&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;PORT&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;5432&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: I won't cover how to create a database schema with Postgres. You can look that up in a video tutorial.&lt;/p&gt;

&lt;h3&gt;
  
  
  Migration
&lt;/h3&gt;

&lt;p&gt;After installation and configuration, what is next? yes, you got it. we need to make migrations. this is because we now have a fresh and clean database instance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;makemigrations&lt;/strong&gt;: we need to run this command &lt;code&gt;python manage.py makemigrations&lt;/code&gt; . This command is used to create new migrations files based on the changes detected in the models. These migration files can then be used to create or modify the database schema to match the current state of the model.&lt;/p&gt;

&lt;p&gt;then we will run the migrate command: &lt;code&gt;python manage.py migrate&lt;/code&gt; when you run this command, Django will look at the migration field that was created by the makemigrations command and use them to create and modify the database schema.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Now that we understand how to set up our database, it is also advisable to make more research to get a better view and understanding of databases.  &lt;/p&gt;

&lt;p&gt;You can follow me on &lt;a href="https://twitter.com/akoladesoft" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;, I write about Django weekly.. &lt;strong&gt;cheers and happy coding&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>design</category>
      <category>oop</category>
    </item>
    <item>
      <title>Models in Django</title>
      <dc:creator>Akolade</dc:creator>
      <pubDate>Tue, 17 Jan 2023 12:42:52 +0000</pubDate>
      <link>https://dev.to/akolade/models-in-django-1kli</link>
      <guid>https://dev.to/akolade/models-in-django-1kli</guid>
      <description>&lt;p&gt;One of the key features of Django is it use of models, which are used to represent the data in a Django application. Now before we move, this is a continuation of my Django Basics series, you can read them &lt;a href="https://dev.to/akolade"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What are Models
&lt;/h3&gt;

&lt;p&gt;Models in Django are defined as Python classes that inherit from the &lt;strong&gt;django.db.models.Model&lt;/strong&gt; class. Each class represents a table in the database, and each attribute of the class represents a column in the table.&lt;/p&gt;

&lt;p&gt;did I lose you with that definition? okay, let's make it simpler&lt;/p&gt;

&lt;p&gt;Model is a python class that defines the fields and behavior of the data you will be storing. these python classes or models are defined in the models.py file of your app and are used to structure and interact with the database.&lt;/p&gt;

&lt;p&gt;Django provides a built-in Object-Relational Mapping (ORM) system, which allows you to interact with the database using Python code instead of writing raw SQL queries. This means that you can create, read, update, and delete database records using Python methods&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating a Model
&lt;/h3&gt;

&lt;p&gt;It is quite easy to create a model just like defining a class in python, but there is more to it, we also need to define the fields in the model. for example, if you were building a simple blog application, you might have a model for the blog posts, which would look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django.db&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Author&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CharField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;bio&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TextField&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;email&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;EmailField&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;created_at&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DateTimeField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;auto_now_add&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;updated_at&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DateTimeField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;auto_now&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
     &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__str__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CharField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TextField&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;pub_date&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DateTimeField&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;author&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ForeignKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Author&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;on_delete&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CASCADE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;created_at&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DateTimeField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;auto_now_add&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;updated_at&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DateTimeField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;auto_now&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
     &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__str__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This model defines two classes: &lt;code&gt;Author&lt;/code&gt; and &lt;code&gt;Post&lt;/code&gt; which both inherit from &lt;code&gt;models.Model&lt;/code&gt;, this tells Django that the classes should be treated as models and that they should be stored in the database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Author&lt;/strong&gt; class defines the fields and behavior of the Author data and it has 5 fields:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;name&lt;/code&gt;: This is a &lt;code&gt;CharField&lt;/code&gt; which is used to store character data (i.e. strings) in the database. The &lt;code&gt;max_length&lt;/code&gt; parameter specifies the maximum number of characters that can be stored in this field.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;bio&lt;/code&gt;: This is a &lt;code&gt;TextField&lt;/code&gt; which is used to store large amounts of text in the database.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;email&lt;/code&gt;: This is a &lt;code&gt;EmailField&lt;/code&gt; which is used to store email addresses, it will validate the email format.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;created_at&lt;/code&gt;: This is a &lt;code&gt;DateTimeField&lt;/code&gt; which is used to store date and time information, the &lt;code&gt;auto_now_add&lt;/code&gt; argument is set to &lt;code&gt;True&lt;/code&gt; which means that the field will be set to the current date and time when the model instance is first created.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;updated_at&lt;/code&gt;: This is a &lt;code&gt;DateTimeField&lt;/code&gt; which is used to store date and time information, the &lt;code&gt;auto_now&lt;/code&gt; argument is set to &lt;code&gt;True&lt;/code&gt; which means that the field will be set to the current date and time every time the model instance is saved.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Post&lt;/strong&gt;: This class defines the fields and behaviour of the Post data. it has six fields&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;title&lt;/code&gt;: This is a &lt;code&gt;CharField&lt;/code&gt; which is used to store a short title for the post.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;content&lt;/code&gt;: This is a &lt;code&gt;TextField&lt;/code&gt; which is used to store the content of the post.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;pub_date&lt;/code&gt;: This is a &lt;code&gt;DateTimeField&lt;/code&gt; which is used to store the publication date and time of the post.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;author&lt;/code&gt;: This is a &lt;code&gt;ForeignKey&lt;/code&gt; which is used to establish a one-to-many relationship between the &lt;code&gt;Post&lt;/code&gt; model and the &lt;code&gt;Author&lt;/code&gt; model. It means that each post is associated with a single author.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;created_at&lt;/code&gt; and &lt;code&gt;updated_at&lt;/code&gt;: the same meaning as that of Author&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Model Method
&lt;/h3&gt;

&lt;p&gt;Both classes define a &lt;code&gt;__str__&lt;/code&gt; method, which returns a string representation of the object, this method is used when the object is displayed in the Django admin interface or when the object is returned by a query.&lt;/p&gt;

&lt;h3&gt;
  
  
  Django Fields
&lt;/h3&gt;

&lt;p&gt;For better understanding, it is necessary to define what those fields we just use are and also state some examples&lt;/p&gt;

&lt;p&gt;Fields are used to define the data that a model should store.&lt;/p&gt;

&lt;p&gt;The field class defines the type of data that the field will store, as well as any constraints or validation that should be applied to that data. The data for each field is stored in the corresponding database table, fields are used to define the structure of the table and the type of data that is stored in each column.&lt;/p&gt;

&lt;h3&gt;
  
  
  Types of Fields
&lt;/h3&gt;

&lt;p&gt;Django provides a variety of built-in field classes for common data types such as text, numbers, dates, and files. Some examples of these field classes are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;CharField&lt;/code&gt;: used to store character data, such as a name or a title.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;TextField&lt;/code&gt;: used to store large amounts of text, such as a blog post or a description.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;IntegerField&lt;/code&gt;: used to store integers, such as the number of views or likes on a post.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;DateField&lt;/code&gt;: used to store a date without a time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;DateTimeField&lt;/code&gt;: used to store a date and time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;DecimalField&lt;/code&gt;: used to store decimal numbers, such as currency values.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;FileField&lt;/code&gt;: used to store files, such as images or documents.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ImageField&lt;/code&gt;: used to store images, this field is a subclass of &lt;code&gt;FileField&lt;/code&gt; with some additional validation for image file types.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each field class has its own set of optional arguments that can be used to customize its behavior. Some of the most common arguments are&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;max_length&lt;/code&gt;: This argument is used to specify the maximum number of characters that can be stored in a field. It is typically used with &lt;code&gt;CharField&lt;/code&gt; and &lt;code&gt;TextField&lt;/code&gt; fields.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;default&lt;/code&gt;: This argument is used to specify a default value for the field. This value will be used when creating a new model instance if no value is provided for the field. It can be a value or a callable that returns a value.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;null&lt;/code&gt;: This argument is used to specify whether or not the field can be empty (&lt;code&gt;NULL&lt;/code&gt;) in the database. The default value is &lt;code&gt;False&lt;/code&gt;, which means that the field cannot be empty.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;blank&lt;/code&gt;: This argument is used to specify whether or not the field can be left blank in forms. The default value is &lt;code&gt;False&lt;/code&gt;, which means that the field must be filled in when the form is submitted.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;choices&lt;/code&gt;: This argument is used to specify a list of valid choices for the field. It should be a list of 2-tuples, where the first element is the value to be stored in the database and the second element is the human-readable label.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;auto_now&lt;/code&gt;: This argument is used to automatically set the field to the current date and time every time the model instance is saved.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;auto_now_add&lt;/code&gt;: This argument is used to automatically set the field to the current date and time when the model instance is first created.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;on_delete&lt;/code&gt; : is used to specify what should happen when the referenced object (i.e. the object on the other side of a foreign key or many-to-many relationship) is deleted. It is used in fields such as &lt;code&gt;ForeignKey&lt;/code&gt; and &lt;code&gt;OneToOneField&lt;/code&gt; and it is a required argument.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can also use fields to establish relationships between models, for example, you can use a &lt;code&gt;ForeignKey&lt;/code&gt; field to establish a one-to-many relationship between two models, or you can use a &lt;code&gt;ManyToManyField&lt;/code&gt; to establish a many-to-many relationship.&lt;/p&gt;




&lt;p&gt;Since you got to this point, now let's re-create the Post model again and add more structure and fields.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;

    &lt;span class="n"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;draft&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Draft&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;published&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Published&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CharField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;unique&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TextField&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;pub_date&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DateTimeField&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;author&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ForeignKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Author&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;on_delete&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CASCADE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;related_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Posts&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;slug&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SlugField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;unique_for_date&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;publish&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CharField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;choices&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;option&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;draft&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;created_at&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DateTimeField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;auto_now_add&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;updated_at&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DateTimeField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;auto_now&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__str__&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;

    &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Meta&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;ordering&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;-publish&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let me explain:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;options&lt;/code&gt; : A tuple of tuples that define the valid options for the &lt;code&gt;status&lt;/code&gt; field, the first element of each tuple is the stored value in the database and the second is the human-readable label.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;title&lt;/code&gt;: A &lt;code&gt;CharField&lt;/code&gt; that is used to store the title of the article. The &lt;code&gt;max_length&lt;/code&gt; argument is set to 255 characters and the &lt;code&gt;unique&lt;/code&gt; argument is set to &lt;code&gt;True&lt;/code&gt;, this means that the title must be unique among all articles.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;slug&lt;/code&gt;: A &lt;code&gt;SlugField&lt;/code&gt; that is used to store a short, URL-friendly version of the title. The &lt;code&gt;max_length&lt;/code&gt; argument is set to 255 characters, and the &lt;code&gt;unique_for_date&lt;/code&gt; argument is set to &lt;code&gt;'publish'&lt;/code&gt;, this means that the slug must be unique among all articles for a given date.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;author&lt;/code&gt;: A &lt;code&gt;ForeignKey&lt;/code&gt; that is used to establish a relationship between the &lt;code&gt;Post&lt;/code&gt; model and the &lt;code&gt;Author&lt;/code&gt; model. This field is used to store the Author who created the article, the &lt;code&gt;on_delete&lt;/code&gt; argument is set to &lt;code&gt;models.CASCADE&lt;/code&gt;, which means that when the user is deleted, all the articles associated to him will be deleted as well.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;status&lt;/code&gt;: A &lt;code&gt;CharField&lt;/code&gt; that is used to store the current status of the article, such as 'draft' or 'published'. The &lt;code&gt;max_length&lt;/code&gt; argument is set to 16 characters, the &lt;code&gt;choices&lt;/code&gt; argument is set to &lt;code&gt;options&lt;/code&gt;, this means that the valid choices are the ones defined in the options tuple and the &lt;code&gt;default&lt;/code&gt; argument is set to 'draft', which means that if no status is specified, the default status will be 'draft'.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Wow, you made it here. Thank you.&lt;/p&gt;

&lt;p&gt;In the next article, I will write about databases - types, configuration and migration&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Till Then ----- Happy Coding&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>github</category>
      <category>webdev</category>
      <category>developers</category>
    </item>
    <item>
      <title>Writing Views in Django</title>
      <dc:creator>Akolade</dc:creator>
      <pubDate>Wed, 11 Jan 2023 13:13:33 +0000</pubDate>
      <link>https://dev.to/akolade/writing-views-in-django-3634</link>
      <guid>https://dev.to/akolade/writing-views-in-django-3634</guid>
      <description>&lt;p&gt;In Django, a view is a Python function that takes a web request and returns a web response. The response can be in the form of HTML, JSON, XML, Image or anything at all. Yes anything&lt;/p&gt;

&lt;p&gt;Below is a simple view that displays a message to the user&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django.http&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;HttpResponse&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;HttpResponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Hello, World!&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code above is simply returning an HTTP response, but rendering templates is quite similar and easy.&lt;/p&gt;

&lt;p&gt;Views are an important part of any Django application because they handle the logic of your application. They are responsible for processing requests, interacting with &lt;strong&gt;models&lt;/strong&gt; to retrieve data, and returning a response to the client.&lt;/p&gt;

&lt;p&gt;Don't stress too much about &lt;strong&gt;models&lt;/strong&gt; read my next article, I will write about it&lt;/p&gt;

&lt;p&gt;To create a view in Django, you will need to define a function in your app's &lt;code&gt;views.py&lt;/code&gt; file and map it to a URL pattern. For example, let's say you want to create a view that displays a list of blog posts. You could define a view like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django.shortcuts&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;render&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;.models&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;BlogPost&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;list_posts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;BlogPost&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;objects&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;blog/list_posts.html&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;posts&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This view uses the Django ORM to retrieve all blog posts from the database and passes them to a template to be rendered.&lt;/p&gt;

&lt;p&gt;To map this view to a URL, you will need to create a file called &lt;code&gt;urls.py&lt;/code&gt; in your app directory and define a URL pattern then import views into the file. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django.urls&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;.&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;views&lt;/span&gt;

&lt;span class="n"&gt;urlpatterns&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nf"&gt;path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;posts/&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;views&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;list_posts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;list_posts&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a URL pattern that maps the &lt;code&gt;/posts/&lt;/code&gt; URL to the &lt;code&gt;list_posts&lt;/code&gt; view.&lt;/p&gt;

&lt;p&gt;In addition to simple views like the one shown above, it is important to note that Django also supports &lt;strong&gt;class-based views&lt;/strong&gt;, which are classes that inherit from the &lt;code&gt;View&lt;/code&gt; class and implement one or more methods to handle different types of requests. For example, you could create a class-based view for the &lt;code&gt;list_posts&lt;/code&gt; view like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django.views.generic&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ListView&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;.models&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;BlogPost&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ListPostsView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ListView&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;BlogPost&lt;/span&gt;
    &lt;span class="n"&gt;template_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;blog/list_posts.html&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
    &lt;span class="n"&gt;context_object_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;posts&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This view will handle the same functionality as the function-based view, but it is organized as a class with separate methods for handling different types of requests (e.g. &lt;code&gt;get&lt;/code&gt;, &lt;code&gt;post&lt;/code&gt;, &lt;code&gt;put&lt;/code&gt;, etc.).&lt;/p&gt;

&lt;h3&gt;
  
  
  Simple Definition of Django ORM
&lt;/h3&gt;

&lt;p&gt;Django ORM: Django Object Relational Mapper is like a helper that makes it easy for people (programmers) to talk to a computer program (database) and ask it to remember things like a list, but instead of writing a lot of confusing codes, they use simple words that the helper (ORM) understand and then it translates it to the computer language that it can understand.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;There are many more advanced concepts you can explore with Django views, such as decorators, generic views, and view mixins. There is no point jumping into this now, we can always learn along the way.&lt;/p&gt;

&lt;p&gt;For broader information about Django views, you can refer to the documentation.&lt;/p&gt;

</description>
      <category>firstpost</category>
      <category>community</category>
      <category>career</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Everything you need to know about Django(Python) as a Beginner.</title>
      <dc:creator>Akolade</dc:creator>
      <pubDate>Tue, 03 Jan 2023 13:18:35 +0000</pubDate>
      <link>https://dev.to/akolade/everything-you-need-to-know-about-djangopython-as-a-beginner-5e9j</link>
      <guid>https://dev.to/akolade/everything-you-need-to-know-about-djangopython-as-a-beginner-5e9j</guid>
      <description>&lt;p&gt;As a newbie, forget all the noise and learn Django for backend web development (well do your research and see what is suitable for you).&lt;/p&gt;

&lt;p&gt;Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of web development, so you can focus on writing your app without needing to reinvent the wheel. In this article, we'll cover everything a beginner needs to know about Django.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Django
&lt;/h3&gt;

&lt;p&gt;Django is a powerful, free and open-source Python web framework that simplifies the development of complex, database-driven websites. Some of the notable sites that use Django are Dropbox, Instagram, NASA, Mozilla, and Disqus.&lt;/p&gt;

&lt;p&gt;Django follows the “batteries included” philosophy, which means that it comes with a lot of built-in features, such as, an ORM (Object-Relational Mapper), authentication, multiple database support and security which allows a developer to generate a powerful website as quickly as possible&lt;/p&gt;

&lt;p&gt;One of the main benefits of using Django is its emphasis on convention over configuration, which means that it has a set of pre-defined conventions for things like project layout and database schema, so you don’t have to spend a lot of time configuring your application. This makes it easy for new developers to get up and running quickly.&lt;/p&gt;

&lt;p&gt;Now let's dive in.&lt;br&gt;
&lt;a href="https://i.giphy.com/media/OuePMznpbHyrw34608/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/OuePMznpbHyrw34608/giphy.gif" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Installation and Setup
&lt;/h3&gt;

&lt;p&gt;To start using Django, you need to have Python installed on your system. You can check if you have Python installed by running the following command in your terminal: &lt;code&gt;python --version&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you don't have Python installed, you can download it from the official Python website (&lt;a href="https://www.python.org/" rel="noopener noreferrer"&gt;&lt;strong&gt;https://www.python.org/&lt;/strong&gt;&lt;/a&gt;) and follow the installation instructions.&lt;/p&gt;

&lt;p&gt;Once Python is installed, you need to choose a directory for your project: and then open your terminal or Powershell and run the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;cd&lt;/span&gt; &lt;span class="n"&gt;desktop&lt;/span&gt;  &lt;span class="c1"&gt;# or documents or anywhere you want
&lt;/span&gt;
&lt;span class="c1"&gt;# you can then create a folder for your project and cd into the folder
&lt;/span&gt;&lt;span class="n"&gt;mkdir&lt;/span&gt; &lt;span class="n"&gt;django&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;project&lt;/span&gt;
&lt;span class="n"&gt;cd&lt;/span&gt; &lt;span class="n"&gt;django&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;project&lt;/span&gt;

&lt;span class="c1"&gt;# open vscode 
&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before we install Django we need to install and activate a virtual environment. Think of the virtual environment as a container that helps us isolate our project dependencies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# install the virtual environment
&lt;/span&gt;&lt;span class="n"&gt;pip&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="n"&gt;virtualenv&lt;/span&gt;

&lt;span class="c1"&gt;# create the virtual environment
&lt;/span&gt;&lt;span class="n"&gt;virtualenv&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt; 

&lt;span class="c1"&gt;# to activate the virtual environment (on windows) 
&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;\&lt;span class="n"&gt;Scripts&lt;/span&gt;\&lt;span class="n"&gt;activate&lt;/span&gt;

&lt;span class="c1"&gt;# activating the virtual environment (on macOS) 
&lt;/span&gt;&lt;span class="n"&gt;source&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nb"&gt;bin&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;activate&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's install Django. You can do this by running the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;pip&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="n"&gt;django&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Django project structure
&lt;/h3&gt;

&lt;p&gt;Once Django is installed, you can create a new project by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;django&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;admin&lt;/span&gt; &lt;span class="n"&gt;startproject&lt;/span&gt; &lt;span class="n"&gt;myproject&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a new directory called "myproject" with the basic structure of a Django project. A Django project consists of one or more apps, and each app can have multiple models, views, and templates.&lt;/p&gt;

&lt;p&gt;Here's a breakdown of the main directories and files in a Django project:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;manage.py&lt;/code&gt; : A command-line utility that lets you interact with this Django project in various ways.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;__init__.py&lt;/code&gt; &lt;strong&gt;:&lt;/strong&gt; An empty file that tells Python that this directory should be considered as a Python package.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;settings.py&lt;/code&gt; : settings for this Django project, such as database configurations, installed apps and middleware.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;urls.py&lt;/code&gt; : The URL declarations for this Django Project&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;asgi.py&lt;/code&gt; : An entry point for ASGI-compatible web servers to serve your project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;wsgi.py&lt;/code&gt; : An entry point for WSGI-compatible web servers to serve your project&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now run your basic server using this command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;python&lt;/span&gt; &lt;span class="n"&gt;manage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt; &lt;span class="n"&gt;runserver&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output of the command should be visible in your broswer with this link- &lt;a href="https://127.0.0.1:8000" rel="noopener noreferrer"&gt;https://127.0.0.1:8000&lt;/a&gt; like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fybjh3qsqoxg01li6rc99.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fybjh3qsqoxg01li6rc99.png" alt="Image description" width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, you will need to create a Django "app" within your project. An app is a self-contained unit of code that performs a specific function in your project. You can create an app by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;python&lt;/span&gt; &lt;span class="n"&gt;manage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt; &lt;span class="n"&gt;startapp&lt;/span&gt; &lt;span class="n"&gt;myapp&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a new directory called "myapp" with the basic structure of a Django app. The most important file in this directory is &lt;code&gt;views.py&lt;/code&gt;, which contains functions that handle requests and return responses.&lt;/p&gt;

&lt;p&gt;Your setup should look like this :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnlmbme9xpvxutxkxlaw8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnlmbme9xpvxutxkxlaw8.png" alt="Image description" width="800" height="850"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To create a view, you will need to define a function in &lt;code&gt;views.py&lt;/code&gt; and map it to a URL pattern. To do this, you will need to create a file called &lt;code&gt;urls.py&lt;/code&gt; in your app directory and define a URL pattern. For example:&lt;/p&gt;

&lt;h3&gt;
  
  
  views.py
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django.shortcuts&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;render&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django.http&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;HttpResponse&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;index&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;templates/index.html&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  urls.py
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django.urls&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;.&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;views&lt;/span&gt;

&lt;span class="n"&gt;urlpatterns&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nf"&gt;path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;views&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;index&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a URL pattern that maps the root URL (&lt;code&gt;/&lt;/code&gt;) to the &lt;code&gt;index&lt;/code&gt; function in &lt;code&gt;views.py&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To display the results of your view in a template, you will need to create a template and render it in your view. Django uses the Django Template Language (DTL) to render templates. You can create a template by creating a &lt;code&gt;templates&lt;/code&gt; directory in your app directory and create an &lt;code&gt;index.html&lt;/code&gt; file inside it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Hello, Django!&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In your project urls.py file, You also need to include your app's urls&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django.urls&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;include&lt;/span&gt;

&lt;span class="n"&gt;urlpatterns&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nf"&gt;path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;admin/&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;admin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;site&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;urls&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="nf"&gt;path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;myapp&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;include&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;myapp.urls&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Now let's register the app and also define our templates path in settings.py
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;INSTALLED_APPS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;django.contrib.admin&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;django.contrib.auth&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;django.contrib.contenttypes&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;django.contrib.sessions&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;django.contrib.messages&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;django.contrib.staticfiles&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;myapp&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;TEMPLATES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;BACKEND&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;django.template.backends.django.DjangoTemplates&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;DIRS&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BASE_DIR&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;templates&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)],&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;APP_DIRS&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;OPTIONS&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;context_processors&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
                &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;django.template.context_processors.debug&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;django.template.context_processors.request&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;django.contrib.auth.context_processors.auth&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;django.contrib.messages.context_processors.messages&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Django is a powerful and feature-rich web framework that is well-suited for building a wide range of applications.&lt;/p&gt;

&lt;p&gt;If you're just starting out with Django, it's important to take the time to learn the basics and get familiar with the framework before diving into more advanced concepts.&lt;/p&gt;

&lt;p&gt;This is just a basic overview of how Django works. There is a lot more to learn, such as working with models, databases, forms, static files, and authentication, but these concepts should give you a good foundation to start building your own Django.&lt;/p&gt;

&lt;p&gt;To learn more about Django check this tutorial by &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django" rel="noopener noreferrer"&gt;Mozilla&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Also check this youtube tutorial: &lt;a href="https://www.youtube.com/watch?v=UsUriZLCwws" rel="noopener noreferrer"&gt;Django with Mosh&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Check out my &lt;a href="https://twitter.com/akoladesoft" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; page, I write about Python and Django.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/xUA7aN1MTCZx97V1Ic/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/xUA7aN1MTCZx97V1Ic/giphy.gif" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>emptystring</category>
    </item>
    <item>
      <title>My First Project: A personal Ecommerce Website</title>
      <dc:creator>Akolade</dc:creator>
      <pubDate>Sun, 13 Nov 2022 12:37:35 +0000</pubDate>
      <link>https://dev.to/akolade/my-first-project-a-personal-ecommerce-website-394p</link>
      <guid>https://dev.to/akolade/my-first-project-a-personal-ecommerce-website-394p</guid>
      <description>&lt;p&gt;Whoopssss: I built my first project as a developer..&lt;/p&gt;

&lt;p&gt;This Project took a little over a month to conceptualize and complete.&lt;/p&gt;

&lt;p&gt;The Tech stack used are: Python, Django, Postgres, HTML, CSS, JavaScript, AWS, Heroku.&lt;/p&gt;

&lt;p&gt;Now down to the functionalities and features of the website&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User Authentication and Authorization:
Users can decide to create an account with their google, Facebook, Twitter account(I used &lt;strong&gt;Django allauth&lt;/strong&gt; for this and the third party API’s) or users can just create an account with an email. Once user is logged on, they won’t have access to to login/signup page.
Additionally, there is logic that enables Users who choose not to register to still go on with business.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="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%2F5vowl66aegaylnimfcjl.gif" class="article-body-image-wrapper"&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%2F5vowl66aegaylnimfcjl.gif" alt="User Auth" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add to Cart and Checkout: 
Users, both authenticated and unauthenticated, will be able to add and remove items from their carts before proceeding to checkout.
A cookie was used to handle the checkout and cart page for an unauthenticated customer. Even if they leave the page for a while, their cart will still be intact.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="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%2Fcwf5y2df9z91p0nex8pd.gif" class="article-body-image-wrapper"&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%2Fcwf5y2df9z91p0nex8pd.gif" alt="Add to cart" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Payment Integration:
Payments can be made using a debit card or a PayPal account (I initially used paystack which worked perfectly , but I wanted something more universal). I am still looking at how to add more than one payment platform.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="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%2F364ktplapx30s1j9fgbr.gif" class="article-body-image-wrapper"&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%2F364ktplapx30s1j9fgbr.gif" alt="payment" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Visitors can subscribe to a newsletter by entering their name and email address, and the data is collected in the backend. There is also a functionality that checks if the email has already been used.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Product Collections page is dynamically rendered, and I plan to add dynamic product details pages for each product later.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Challenges Faced&lt;/strong&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The first issue was that after creating a customer / user, the customer was unable to access the collections, checkout, and cart page. I keep getting this error &lt;strong&gt;RelatedObjectDoesNotExist&lt;/strong&gt;. After reading various documentation, research, and thinking, I finally conquered It in 3-4 days, with the solution being as simple as one line of code. I only had to create and assign the user.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Postgres and AWS: It took me three days to finally get this thing. Postgres keeps giving server connection  error. AWS free tier charged my card I don’t know why(the small money I was managing)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There are many other challenges but let’s us leave it at this.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Well building this project really taught me what really happen on the backend. I can now say that building a project will really teach you a lot.. enough of blazing through tutorials, start building and make research.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next Project&lt;/strong&gt; should either be a portfolio website, CRUD app or Payroll management system(I was formerly an HR so this will be fun). &lt;/p&gt;

&lt;p&gt;You can follow me on &lt;a href="https://twitter.com/AkoladeSoft"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also check out my github profile: &lt;a href="https://github.com/emmakolade"&gt;emmakolade&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you for reading through.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>webdev</category>
      <category>python</category>
      <category>django</category>
    </item>
  </channel>
</rss>
