Django Basics




Creating a new Django project:

Install Django: Before creating a new project, make sure you have Django installed. You can install it using pip, the Python package manager, by running pip install django in your terminal or command prompt.

Create a new project: Once Django is installed, you can create a new project by running django-admin startproject project_name in your terminal or command prompt. Replace project_name with the name you want to give your project.

Understanding project structure:

project_name/: This is the main project directory. It contains settings for your project, including database configuration, URL routing, and more.

manage.py: This is a command line tool for your Django project. It allows you to manage development servers, create apps and perform many other tasks.

project_name/: This directory is the actual Python package for your project. Inside this directory you will find settings.py which contains configuration settings for your project, urls.py which contains URL routing information and other files such as asgi.py and wsgi.py for ASGI and WSGI server interfaces.

Running the development server:

Once your project is set up, you can run the development server to preview your application:

In your terminal or command prompt, navigate to the project directory.

Run python manage.py runserver. This starts the Django development server which listens for HTTP requests on your local machine.

With the server running, open a web browser and go to http://127.0.0.1:8000/ (or http://localhost:8000/). You should see the default Django welcome page, indicating that the server was set up correctly.