Django is a high-level framework, written in Python, that encourages clean web application development. It is a free and open source project with an active developer community and extensive documentation. In this chapter, we'll cover creating a Django project, starting with installing Django.
Django Installation
To start creating your Django project, the first thing you need to do is install Django in your development environment. Installation is a simple and straightforward process, which can be performed by following the steps below:
Python Installation
Django is a Python framework, so before installing Django, you need to have Python installed on your computer. If you don't have Python installed yet, you can download it from the official Python website https://www.python.org/downloads/ . Once downloaded, run the installer and follow the on-screen instructions to install Python.
Django Installation
With Python installed, you can now install Django. Django can be installed using pip, which is a package management system used to install and manage software packages written in Python.
To install Django, open a terminal and type the following command:
$ pip install Django
This command will download and install the latest stable version of Django. If you want to install a specific version of Django, you can specify the version after the package name. For example, to install Django version 2.2, you could use the following command:
$ pip install Django==2.2
Creating a Django Project
With Django installed, you're ready to create your first Django project. A Django project is the collection of settings and applications for a given website. A Django application is a Python module that plugs into a Django project and provides specific functionality.
To create a new Django project, open the terminal and navigate to the directory where you want to create the project. Then, use the following command:
$ django-admin startproject project_name
Replace "project_name" with the name you want to give your project. This command will create a new directory named after your project, which contains the basic structure of a Django project.
Running the Development Server
Once you've created your project, you can run the Django development server to see your project in action. The development server is a lightweight web server that serves your website pages locally - perfect for development.
To run the development server, navigate to your project directory and use the following command:
$ python manage.py runserver
This will start the development server at http://127.0.0.1:8000/. If you open this address in your browser, you'll see Django's welcome page, confirming that your project was successfully created and running.
Conclusion
In this chapter, we cover installing Django and creating a new Django project. You are now ready to start developing your site with Django. In the next chapter, we'll cover creating Django applications and the structure of a Django project.