Django Installation

beginner
10 min

Django Installation

Welcome to the Django Installation tutorial! In this lesson, we'll walk you through the process of installing Django, a powerful and versatile Python web framework. By the end of this tutorial, you'll be ready to dive into building your first Django project! 🎯

What is Django?

Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. It's built by experienced developers and is used by some of the world's biggest companies, including Instagram and Pinterest.

πŸ’‘ Pro Tip: Django makes it easy to build complex, database-driven websites quickly and efficiently, perfect for self-learners and professionals alike!

Before We Begin

To follow along with this tutorial, you'll need:

  • Python 3.x installed on your system
  • A text editor (such as Visual Studio Code, Atom, or Sublime Text)

Installing Django

Now that we've covered the basics, let's get started! To install Django, open your terminal or command prompt and type:

bash
pip install django

πŸ“ Note: If you encounter any issues during the installation, make sure you have the latest version of pip installed. You can update pip by running pip install --upgrade pip.

Creating Your First Django Project

Once Django is installed, you can create a new project. In the terminal, navigate to the directory where you want to create your project, and run:

bash
django-admin startproject mysite

Replace mysite with the name you'd like to call your project.

Quick Quiz
Question 1 of 1

What command do you use to create a new Django project?

Exploring Your Django Project

Navigate into your new project directory:

bash
cd mysite

Inside your project directory, you'll find several key files and directories. The most important ones are:

  • manage.py: A utility script for managing your Django project
  • mysite/: The main project directory, containing various subdirectories
    • mysite/settings.py: Settings for your project
    • mysite/urls.py: URL routing for your project

Running Your First Django Server

Before we move on, let's ensure that Django is working correctly. In the terminal, navigate to the project directory and run:

bash
python manage.py runserver

If everything goes well, you should see output similar to this:

Watching for file changes with StatReloader Performing system check... System check identified no issues (0 silenced). You have 14 unapplied migration(s). Your project may not work correctly until you apply the migrations for app(s): admin, auth, contenttypes, sessions. Run 'python manage.py migrate' to apply them. May 23, 2023 - 13:00:00 Django version 3.2.6, using settings 'mysite.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK.

Now, open your web browser and navigate to http://127.0.0.1:8000/. You should see the Django welcome page, confirming that your installation was successful! πŸŽ‰

Next Steps

In the next lesson, we'll dive deeper into Django by exploring the settings.py file and creating our first Django app. Stay tuned! πŸš€

πŸ“ Note: If you encounter any issues during this tutorial or have questions, don't hesitate to reach out in the comments below. Happy learning! πŸ€“