MY STRUGGLE WITH USING DJANGO FRAMEWORK AT FIRST AND THE SIMPLEST STEPS TO CREATE A SIMPLE APP IN DJANGO

arbythecoder

Arbythecoder

Posted on September 14, 2023

MY STRUGGLE WITH USING DJANGO FRAMEWORK AT FIRST AND THE SIMPLEST STEPS TO CREATE A SIMPLE APP IN DJANGO

It took me a while (if only I could elongate “a while” to express how long it actually took me🤣) to discover the steps required to create a simple Django app (my first was a blog app), but when I did, life became easier for me.

So, here are the simple steps to create a Django app. Once you’re familiar with these steps, Django becomes as easy as child’s play:

STEP 1: Installing Python and Django

First, you must have Python installed on your computer. You can install Django using pip:

pip install django
Enter fullscreen mode Exit fullscreen mode

Confirm that you’ve installed Django correctly by running this command:

django-admin — version
Enter fullscreen mode Exit fullscreen mode

STEP 2: Creating Your Project

Now, you’ll need to create your project by using this command (replace “Arby” with your project name):

django-admin startproject Arby
Enter fullscreen mode Exit fullscreen mode

In Django, when you create a project, you create your apps inside your project. The amazing thing is that in one Django project, you can have multiple apps, and you’re still good to go!

STEP 3: Creating Your App

It’s time to create your app using this command:

python manage.py startapp arbysApp
Enter fullscreen mode Exit fullscreen mode

Make sure you change your working directory to your project first before doing this, or it will be a struggle 😞 (I had a bit of a struggle with this when I started learning Django too).

STEP 4: Configuring Your Database

You need to let your database understand that you now have an app present (database configurations). Click on your project and observe there’s a Python file called ‘settings.py’. Scroll to where INSTALLED APPS are and add your app ‘arbyApp’ to it. For this explanation, we’ll stick to SQLite as all necessary connection settings are in place already.
STEP 5: Creating Your Models

Django models are like the blueprints for your web app’s data. They define how information should be stored and organized. Locate your ‘models.py’ file using Django’s object-relational mapping (ORM).

STEP 6: Applying Migrations

Based on the models you created, you’ll need to migrate for your app to recognize the changes made. Use these commands:

python manage.py makemigrations
python manage.py migrate
Enter fullscreen mode Exit fullscreen mode

Migrations help you manage and understand how your database has changed over time in your web application.

To be continued……

Feel free to reach out to me on my - Reddit

💖 💪 🙅 🚩
arbythecoder
Arbythecoder

Posted on September 14, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related