To create a new Django project, follow these steps:
Install Django: Before starting a new project, install Python on your system. Then, open your terminal or command prompt and install Django using pip like this:
Copy codepip install django
Create the Django project: Once Django is installed, navigate to the directory where you want to create your project and run the following command:
Copy codedjango-admin startproject projectname
Replace "projectname" with the desired name for your Django project. This command will create a new directory with the same name, containing the basic structure of your Django project.
Project structure: After running the above command, you'll have a project directory named "projectname." Inside this directory, you will find the following files and folders:
markdownCopy codeprojectname/ ├── manage.py └── projectname/ ├── __init__.py ├── asgi.py ├── settings.py ├── urls.py └── wsgi.py
Here's a brief overview of these files:
manage.py
: A command-line utility that lets you interact with your project. It runs development servers, executes management commands, and more.projectname/
: This is the main project package containing settings and configurations for your project.__init__.py
: An empty file that designates this directory as a Python package.asgi.py
: ASGI (Asynchronous Server Gateway Interface) configuration for running Django with asynchronous features.settings.py
: Contains project settings, such as database configurations, installed apps, middleware, etc.urls.py
: Defines the URL patterns for your project, mapping URLs to views.wsgi.py
: WSGI (Web Server Gateway Interface) configuration for running Django on WSGI servers.
Database setup (optional): Django uses an SQLite database by default. If you want to use a different database, modify the
settings.py
file to update theDATABASES
setting with the required credentials.Run the development server: To test if your project was created successfully, run the following command:
bashCopy codecd projectname python manage.py runserver
This will start the development server on the default address
http://127.0.0.1:8000/
. You can access this address in your web browser to see the default Django welcome page.
LEARN MORE ON SOURCEBAE
Congratulations! You've created a new Django project and are ready to build your web application.