Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Interview question

What is Django and what is the Django project structure? Django क्या है और Django project का structure क्या है?

Answer

Django is a full-featured, batteries-included web framework for rapid development and clean design. It follows MVT (Model-View-Template) architecture.

myproject/
  manage.py              # Command-line tool
  myproject/
    __init__.py
    settings.py         # Project settings
    urls.py             # URL routing
    wsgi.py             # WSGI application
    asgi.py             # ASGI application
  myapp/
    migrations/
      __init__.py
      0001_initial.py
    __init__.py
    models.py           # Database models
    views.py            # View logic
    urls.py             # App-level routing
    forms.py            # Form definitions
    tests.py            # Unit tests
    admin.py            # Admin interface
    templates/
      myapp/
        index.html
    static/
      css/
        style.css
      js/
        script.js

# Example models.py
from django.db import models

class User(models.Model):
    name = models.CharField(max_length=100)
    email = models.EmailField(unique=True)
    created_at = models.DateTimeField(auto_now_add=True)

# Example views.py
from django.shortcuts import render
from .models import User

def user_list(request):
    users = User.objects.all()
    return render(request, 'myapp/users.html', {'users': users})

# Example urls.py
from django.urls import path
from . import views

urlpatterns = [
    path('users/', views.user_list, name='user_list'),
]

# Commands
# python manage.py startproject myproject
# python manage.py startapp myapp
# python manage.py makemigrations
# python manage.py migrate
# python manage.py runserver
Django project structure:
- manage.py: Command tool
- settings.py: Configuration
- urls.py: URL routing
- models.py: Database models
- views.py: View logic
- templates/: HTML files
- static/: CSS, JS files

MVT Architecture:
- Model: Database layer
- View: Logic/processing
- Template: HTML display

Was this answer clear?