Skip to main content

File Structure

When you create a Django project and app, Django generates several files and directories. Below is an overview of the typical file structure and their purposes.

Project Directory (myproject/)

  • manage.py: A command-line utility to manage your project. Common commands include starting the development server, applying migrations, and creating a superuser.
  • Project Package (myproject/):
    • __init__.py: Marks the directory as a Python package.
    • settings.py: Main configuration file for your project.
    • urls.py: Defines URL patterns for your project.
    • wsgi.py: Entry point for WSGI-compatible web servers in production.
    • asgi.py: Entry point for ASGI-compatible web servers, supporting asynchronous protocols.

App Directory (myapp/)

  • __init__.py: Marks the directory as a Python package.
  • admin.py: Registers models with the Django admin site.
  • apps.py: Contains app-specific configurations.
  • models.py: Defines database models for the app.
  • views.py: Handles HTTP requests and returns responses.
  • urls.py: (Optional) Defines app-specific URL patterns.
  • serializers.py: (For DRF) Converts Python objects to JSON or other formats.
  • tests.py: Contains test cases for the app.
  • migrations/: Tracks database schema changes.

Additional Directories (Optional or Auto-Generated)

  • templates/: Contains HTML templates for rendering views.
  • static/: Contains static assets like CSS, JavaScript, and images.
  • media/: Stores user-uploaded files.

Summary of File Roles

File/DirectoryRole
manage.pyCommand-line utility for project management.
settings.pyCentral configuration for the project.
urls.pyDefines URL routing for the project and apps.
wsgi.py/asgi.pyEntry points for deploying the project.
models.pyDefines database schema using models.
views.pyHandles HTTP requests and returns responses.
serializers.pyDRF-specific file for data serialization.
admin.pyRegisters models with the Django admin site.
tests.pyContains test cases for the app.
migrations/Tracks database schema changes.
templates/Stores HTML templates for rendering data.
static/Contains static assets (CSS, JS, images).
media/Stores uploaded files.