How to create a Django project and app

Django is a powerful web framework that allows developers to quickly create web applications. It is written in Python and is one of the most popular web frameworks available. In this tutorial, we will show you how to create a Django project and app.

Step 1: Install Django

The first step is to install Django. To do this, you will need to have Python installed on your system. Once Python is installed, you can use the pip command to install Django:

pip install django

This will install the latest version of Django on your system.

Step 2: Create a Django Project

Once Django is installed, you can create a new project. To do this, you will need to use the django-admin command. This command will create a new project with the specified name:

django-admin startproject projectname

This will create a new directory with the specified name and all the necessary files for the project.

Step 3: Create a Django App

Once the project is created, you can create a new app. To do this, you will need to use the python manage.py command. This command will create a new app with the specified name:

python manage.py startapp appname

This will create a new directory with the specified name and all the necessary files for the app.

Step 4: Add the App to the Project

Once the app is created, you will need to add it to the project. To do this, you will need to open the settings.py file located in the project directory. In this file, you will need to add the app to the INSTALLED_APPS list:

INSTALLED_APPS = [ ... 'appname',]

This will add the app to the project.

Step 5: Run the Server

Once the app is added to the project, you can run the server. To do this, you will need to use the python manage.py command. This command will start the server:

python manage.py runserver

This will start the server and you can access the application at http://localhost:8000.

Conclusion

In this tutorial, we have shown you how to create a Django project and app. We have also shown you how to add the app to the project and how to run the server. We hope you have found this tutorial helpful.

Useful Links