Installing Django in Django
basic · Django
Setting up Django requires initializing an isolated Python environment, installing the core framework packages, and generating the baseline project directory architecture. Step 1: Verify Python Installation Django is a Python-based framework and requires an active Python installation. Open your terminal or command prompt and verify your Python runtime version: Bash python --version (Ensure your environment runs Python 3.10 or higher for compatibility with modern Django releases). Step 2: Initialize an Isolated Virtual Environment Creating a Virtual Environment ( venv ) is a critical software development best practice. It isolates your project's specific dependency packages from your operating system's global Python installation, preventing package version conflicts between separate applications. Navigate to the directory where you want to store your workspace: Bash cd path/to/your/projects-directory Create a fresh virtual environment container named .venv : Bash python -m venv .venv Activate the isolated environment layer based on your operating system: macOS / Linux: source .venv/bin/activate Windows (Command Prompt): .venv\Scripts\activate.bat Windows (PowerShell): .venv\Scripts\Activate.ps1 Once activated, your terminal prompt will display a (.venv) prefix, indicating that all subsequent package management actions are locked safely inside this isolated container directory. Step 3: Install Django via Pip With the virtual environment active, use Python's package manager ( pip ) to pull down the latest stable compilation of the framework from the official Python Package Index (PyPI): Bash # Upgrade the core package manager installer tools pip install --upgrade pip # Install the Django framework ecosystem packages pip install django To verify that the installation succeeded and inspect the structural framework engine build version, run: Bash django-admin --version Step 4: Generate the Baseline Project Structure Django includes a command-line tool utility called django-admin that automates bootstrapping new application architectures. Run the initialization command below to build your core project workspace directory. Replacing the placeholder name with your own project target name, and include the trailing period ( . ) to initialize the repository layout cleanly inside your active directory without spawning redundant nested folders: Bash django-admin startproject my_enterprise_project The Generated Directory Map The bootstrap utility populates your workspace directory with standard modular configuration modules: Plaintext my_workspace/ # The root container folder ├── manage.py # Command-line execution entry point utility tool ├── .venv/ # Your isolated local third-party package folder └── my_enterprise_project/ ├── __init__.py # Tells Python that this folder is an importable package ├── asgi.py # Asynchronous server deployment interface mapping ├── settings.py # Centralized project configuration management panel ├── urls.py # Global URL path routing registry panel └── wsgi.py # Synchronous WSGI web deployment server interface mapping Step 5: Run the Database Migrations Django comes pre-configured out of the box with a lightweight SQLite configuration layer inside settings.py for local testing. Before launching the web server, run the initial database setup scripts to compile the built-in system tables (such as user administration tables and system logging schemas): Bash python manage.py migrate Step 6: Launch the Local Development Server Start Django's built-in, lightweight local development web server to verify that your system is fully functional: Bash python manage.py runserver Open your web browser and navigate to the local network port address: Plaintext http://127.0.0.1:8000/ Django will render its official onboarding confirmation page, confirming that your environment is fully configured, installed, and ready for code implementation. To shut down the development server loop at any point, press Ctrl + C directly within your active terminal window. How to create app : navigate to the project folder django-admin startapp my_app After creating app register in settings.py INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'your_app', # your app ]