ALL SLIPS CODE : Django practical, slip-wise

Each slip has: question, folder structure, then every file with its path and code.

CONTENTS

  Slip  1 : Pages app, base.html and navbar
  Slip  2 : Bootstrap navbar and static logo
  Slip  3 : Reel model, admin and list page
  Slip  4 : User registration
  Slip  5 : Static images in a dashboard
  Slip  6 : Header, footer and Bootstrap navbar
  Slip  7 : DRF Message list API
  Slip  8 : Student model and list page
  Slip  9 : Teacher model and list page
  Slip 10 : Product model and admin
  Slip 11 : Account model, name and balance
  Slip 12 : DRF Message list API
  Slip 13 : Home link to product list
  Slip 14 : Student model and list page
  Slip 15 : Account model, name and balance
  Slip 16 : DRF Message list API
  Slip 17 : User registration
  Slip 18 : User login and dashboard
  Slip 19 : User registration
  Slip 20 : User login and dashboard

################################################################################
# SLIP 1 : Pages app, base.html and navbar
################################################################################

QUESTION

Time: 3 hours | Marks: 25

1. Create a django project using the admin command. Create and register a pages app. Use template concepts using base.html and create the pages Home, Friends, Posts, Requests. (Each page can have simple content like "I am in home".) [10]
2. Display the pages in a simple navbar. Use URL linking and on each menu click display the corresponding page. [10]
3. Viva [5]

FOLDER STRUCTURE

slip1/
|-- pages/
|   |-- migrations/
|   |   `-- __init__.py
|   |-- __init__.py
|   |-- admin.py
|   |-- apps.py
|   |-- models.py
|   |-- tests.py
|   |-- urls.py
|   `-- views.py
|-- slip1/
|   |-- __init__.py
|   |-- asgi.py
|   |-- settings.py
|   |-- urls.py
|   `-- wsgi.py
|-- templates/
|   |-- pages/
|   |   |-- friends.html
|   |   |-- home.html
|   |   |-- posts.html
|   |   `-- requests.html
|   `-- base.html
`-- manage.py

--------------------------------------------------------------------------------
FILE : settings.py
PATH : slip1/slip1/settings.py
--------------------------------------------------------------------------------
"""
Django settings for slip1 project.

Generated by 'django-admin startproject' using Django 5.2.19.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-njjd2o49c((4zqkj4p*i*(f^e&7rf+5rriwmq64zvs#82*)y0('

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'pages',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'slip1.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR / 'templates'],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'slip1.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/5.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.2/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

--------------------------------------------------------------------------------
FILE : models.py
PATH : slip1/pages/models.py
--------------------------------------------------------------------------------
from django.db import models

# Create your models here.

--------------------------------------------------------------------------------
FILE : admin.py
PATH : slip1/pages/admin.py
--------------------------------------------------------------------------------
from django.contrib import admin

# Register your models here.

--------------------------------------------------------------------------------
FILE : views.py
PATH : slip1/pages/views.py
--------------------------------------------------------------------------------
from django.shortcuts import render


def home(request):
    return render(request, 'pages/home.html')


def friends(request):
    return render(request, 'pages/friends.html')


def posts(request):
    return render(request, 'pages/posts.html')


def friend_requests(request):
    return render(request, 'pages/requests.html')

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip1/pages/urls.py
--------------------------------------------------------------------------------
from django.urls import path
from . import views

urlpatterns = [
    path('', views.home, name='home'),
    path('friends/', views.friends, name='friends'),
    path('posts/', views.posts, name='posts'),
    path('requests/', views.friend_requests, name='requests'),
]

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip1/slip1/urls.py
--------------------------------------------------------------------------------
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('pages.urls')),
]

--------------------------------------------------------------------------------
FILE : base.html
PATH : slip1/templates/base.html
--------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>{% block title %}My Social App{% endblock %}</title>
</head>
<body>
  <nav>
    <a href="{% url 'home' %}">Home</a> |
    <a href="{% url 'friends' %}">Friends</a> |
    <a href="{% url 'posts' %}">Posts</a> |
    <a href="{% url 'requests' %}">Requests</a>
  </nav>
  <hr>

  {% block content %}
  {% endblock %}
</body>
</html>

--------------------------------------------------------------------------------
FILE : friends.html
PATH : slip1/templates/pages/friends.html
--------------------------------------------------------------------------------
{% extends 'base.html' %}

{% block title %}Friends{% endblock %}

{% block content %}
  <h1>I am in friends</h1>
{% endblock %}

--------------------------------------------------------------------------------
FILE : home.html
PATH : slip1/templates/pages/home.html
--------------------------------------------------------------------------------
{% extends 'base.html' %}

{% block title %}Home{% endblock %}

{% block content %}
  <h1>I am in home</h1>
{% endblock %}

--------------------------------------------------------------------------------
FILE : posts.html
PATH : slip1/templates/pages/posts.html
--------------------------------------------------------------------------------
{% extends 'base.html' %}

{% block title %}Posts{% endblock %}

{% block content %}
  <h1>I am in posts</h1>
{% endblock %}

--------------------------------------------------------------------------------
FILE : requests.html
PATH : slip1/templates/pages/requests.html
--------------------------------------------------------------------------------
{% extends 'base.html' %}

{% block title %}Requests{% endblock %}

{% block content %}
  <h1>I am in requests</h1>
{% endblock %}

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip1/pages/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : apps.py
PATH : slip1/pages/apps.py
--------------------------------------------------------------------------------
from django.apps import AppConfig


class PagesConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'pages'

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip1/pages/migrations/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : tests.py
PATH : slip1/pages/tests.py
--------------------------------------------------------------------------------
from django.test import TestCase

# Create your tests here.

--------------------------------------------------------------------------------
FILE : manage.py
PATH : slip1/manage.py
--------------------------------------------------------------------------------
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip1.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip1/slip1/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : asgi.py
PATH : slip1/slip1/asgi.py
--------------------------------------------------------------------------------
"""
ASGI config for slip1 project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip1.settings')

application = get_asgi_application()

--------------------------------------------------------------------------------
FILE : wsgi.py
PATH : slip1/slip1/wsgi.py
--------------------------------------------------------------------------------
"""
WSGI config for slip1 project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip1.settings')

application = get_wsgi_application()

################################################################################
# SLIP 2 : Bootstrap navbar and static logo
################################################################################

QUESTION

Time: 3 hours | Marks: 25

1. Create a new Django project and implement base.html. Create header and footer in base.html. Using {% block content %}{% endblock %} implement "home", "Sales" and "Services" in a Bootstrap navbar. [10]
2. Use the static concept and display a logo in the header. (Download a sample logo or use any system image.) [10]
3. Viva [5]

FOLDER STRUCTURE

slip2/
|-- pages/
|   |-- migrations/
|   |   `-- __init__.py
|   |-- __init__.py
|   |-- admin.py
|   |-- apps.py
|   |-- models.py
|   |-- tests.py
|   |-- urls.py
|   `-- views.py
|-- slip2/
|   |-- __init__.py
|   |-- asgi.py
|   |-- settings.py
|   |-- urls.py
|   `-- wsgi.py
|-- static/
|   `-- images/
|       `-- logo.jpg
|-- templates/
|   |-- pages/
|   |   |-- home.html
|   |   |-- sales.html
|   |   `-- services.html
|   `-- base.html
`-- manage.py

--------------------------------------------------------------------------------
FILE : settings.py
PATH : slip2/slip2/settings.py
--------------------------------------------------------------------------------
"""
Django settings for slip2 project.

Generated by 'django-admin startproject' using Django 5.2.19.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-eb1$n+b4t*r3v$hoxsxll3675795xr1(hntdu9cnj(tn8zf@37'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'pages',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'slip2.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR / 'templates'],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'slip2.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/5.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.2/howto/static-files/

STATIC_URL = 'static/'
STATICFILES_DIRS = [BASE_DIR / 'static']

# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

--------------------------------------------------------------------------------
FILE : models.py
PATH : slip2/pages/models.py
--------------------------------------------------------------------------------
from django.db import models

# Create your models here.

--------------------------------------------------------------------------------
FILE : admin.py
PATH : slip2/pages/admin.py
--------------------------------------------------------------------------------
from django.contrib import admin

# Register your models here.

--------------------------------------------------------------------------------
FILE : views.py
PATH : slip2/pages/views.py
--------------------------------------------------------------------------------
from django.shortcuts import render


def home(request):
    return render(request, 'pages/home.html')


def sales(request):
    return render(request, 'pages/sales.html')


def services(request):
    return render(request, 'pages/services.html')

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip2/pages/urls.py
--------------------------------------------------------------------------------
from django.urls import path
from . import views

urlpatterns = [
    path('', views.home, name='home'),
    path('sales/', views.sales, name='sales'),
    path('services/', views.services, name='services'),
]

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip2/slip2/urls.py
--------------------------------------------------------------------------------
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('pages.urls')),
]

--------------------------------------------------------------------------------
FILE : base.html
PATH : slip2/templates/base.html
--------------------------------------------------------------------------------
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>{% block title %}My Company{% endblock %}</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
  <header class="container py-3">
    <img src="{% static 'images/logo.jpg' %}" alt="Logo" height="60">
    <h2>My Company</h2>
  </header>

  <nav class="navbar navbar-expand navbar-dark bg-dark">
    <div class="container">
      <div class="navbar-nav">
        <a class="nav-link" href="{% url 'home' %}">Home</a>
        <a class="nav-link" href="{% url 'sales' %}">Sales</a>
        <a class="nav-link" href="{% url 'services' %}">Services</a>
      </div>
    </div>
  </nav>

  <main class="container py-4">
    {% block content %}
    {% endblock %}
  </main>

  <footer class="container border-top py-3">
    <p>&copy; 2026 My Company</p>
  </footer>
</body>
</html>

--------------------------------------------------------------------------------
FILE : home.html
PATH : slip2/templates/pages/home.html
--------------------------------------------------------------------------------
{% extends 'base.html' %}

{% block title %}Home{% endblock %}

{% block content %}
  <h1>I am in home</h1>
{% endblock %}

--------------------------------------------------------------------------------
FILE : sales.html
PATH : slip2/templates/pages/sales.html
--------------------------------------------------------------------------------
{% extends 'base.html' %}

{% block title %}Sales{% endblock %}

{% block content %}
  <h1>I am in sales</h1>
{% endblock %}

--------------------------------------------------------------------------------
FILE : services.html
PATH : slip2/templates/pages/services.html
--------------------------------------------------------------------------------
{% extends 'base.html' %}

{% block title %}Services{% endblock %}

{% block content %}
  <h1>I am in services</h1>
{% endblock %}

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip2/pages/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : apps.py
PATH : slip2/pages/apps.py
--------------------------------------------------------------------------------
from django.apps import AppConfig


class PagesConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'pages'

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip2/pages/migrations/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : tests.py
PATH : slip2/pages/tests.py
--------------------------------------------------------------------------------
from django.test import TestCase

# Create your tests here.

--------------------------------------------------------------------------------
FILE : logo.jpg
PATH : slip2/static/images/logo.jpg
--------------------------------------------------------------------------------
(image file, not shown as text. Use: dpythons get 2)

--------------------------------------------------------------------------------
FILE : manage.py
PATH : slip2/manage.py
--------------------------------------------------------------------------------
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip2.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip2/slip2/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : asgi.py
PATH : slip2/slip2/asgi.py
--------------------------------------------------------------------------------
"""
ASGI config for slip2 project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip2.settings')

application = get_asgi_application()

--------------------------------------------------------------------------------
FILE : wsgi.py
PATH : slip2/slip2/wsgi.py
--------------------------------------------------------------------------------
"""
WSGI config for slip2 project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip2.settings')

application = get_wsgi_application()

################################################################################
# SLIP 3 : Reel model, admin and list page
################################################################################

QUESTION

Time: 3 hours | Marks: 25

1. Configure mysql/sqlite DB in a newly created project. Create a model of Reel table having attributes reel_name and caption. [10]
2. Perform migration. Create superuser via admin command and login to the admin panel. Verify whether the table has been created. Using the Admin Panel insert a few Reels. Display all reels on the Reel page. [10]
3. Viva [5]

FOLDER STRUCTURE

slip3/
|-- reel/
|   |-- migrations/
|   |   |-- 0001_initial.py
|   |   `-- __init__.py
|   |-- templates/
|   |   `-- reels.html
|   |-- __init__.py
|   |-- admin.py
|   |-- apps.py
|   |-- models.py
|   |-- tests.py
|   |-- urls.py
|   `-- views.py
|-- slip3/
|   |-- __init__.py
|   |-- asgi.py
|   |-- settings.py
|   |-- urls.py
|   `-- wsgi.py
`-- manage.py

--------------------------------------------------------------------------------
FILE : settings.py
PATH : slip3/slip3/settings.py
--------------------------------------------------------------------------------
"""
Django settings for slip3 project.

Generated by 'django-admin startproject' using Django 5.2.19.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-t_aup459jh5f18!9#4_rihu97+0ta*4l1b097a4b4z-oxl0!3u'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'reel',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'slip3.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'slip3.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/5.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.2/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

--------------------------------------------------------------------------------
FILE : models.py
PATH : slip3/reel/models.py
--------------------------------------------------------------------------------
from django.db import models


class Reel(models.Model):
    reel_name = models.CharField(max_length=100)
    caption = models.CharField(max_length=200)

    def __str__(self):
        return self.reel_name

--------------------------------------------------------------------------------
FILE : admin.py
PATH : slip3/reel/admin.py
--------------------------------------------------------------------------------
from django.contrib import admin
from .models import Reel

admin.site.register(Reel)

--------------------------------------------------------------------------------
FILE : views.py
PATH : slip3/reel/views.py
--------------------------------------------------------------------------------
from django.shortcuts import render
from .models import Reel


def reel_list(request):
    reels = Reel.objects.all()
    return render(request, 'reels.html', {'reels': reels})

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip3/reel/urls.py
--------------------------------------------------------------------------------
from django.urls import path
from . import views

urlpatterns = [
    path('', views.reel_list, name='reel_list'),
]

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip3/slip3/urls.py
--------------------------------------------------------------------------------
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('reel.urls')),
]

--------------------------------------------------------------------------------
FILE : reels.html
PATH : slip3/reel/templates/reels.html
--------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Reel List</title>
</head>
<body>
  <h1>Reel Details</h1>

  <table border="1" cellpadding="6">
    <tr>
      <th>Reel Name</th>
      <th>Caption</th>
    </tr>

    {% for reel in reels %}
    <tr>
      <td>{{ reel.reel_name }}</td>
      <td>{{ reel.caption }}</td>
    </tr>
    {% empty %}
    <tr>
      <td colspan="2">No records found.</td>
    </tr>
    {% endfor %}
  </table>
</body>
</html>

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip3/reel/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : apps.py
PATH : slip3/reel/apps.py
--------------------------------------------------------------------------------
from django.apps import AppConfig


class ReelConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'reel'

--------------------------------------------------------------------------------
FILE : 0001_initial.py
PATH : slip3/reel/migrations/0001_initial.py
--------------------------------------------------------------------------------
# Generated by Django 5.2.19 on 2026-11-25 17:53

from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Reel',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('reel_name', models.CharField(max_length=100)),
                ('caption', models.CharField(max_length=200)),
            ],
        ),
    ]

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip3/reel/migrations/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : tests.py
PATH : slip3/reel/tests.py
--------------------------------------------------------------------------------
from django.test import TestCase

# Create your tests here.

--------------------------------------------------------------------------------
FILE : manage.py
PATH : slip3/manage.py
--------------------------------------------------------------------------------
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip3.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip3/slip3/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : asgi.py
PATH : slip3/slip3/asgi.py
--------------------------------------------------------------------------------
"""
ASGI config for slip3 project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip3.settings')

application = get_asgi_application()

--------------------------------------------------------------------------------
FILE : wsgi.py
PATH : slip3/slip3/wsgi.py
--------------------------------------------------------------------------------
"""
WSGI config for slip3 project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip3.settings')

application = get_wsgi_application()

################################################################################
# SLIP 4 : User registration
################################################################################

QUESTION

Time: 3 hours | Marks: 25

1. Create a new Django project. Change the default view of the project and display login and register hyperlinks. Create a "Register form" using simple HTML tags. [10]
2. Implement code to register/insert user details into SQLite DB and on successful registration display the login page. [10]
3. Viva [5]

FOLDER STRUCTURE

slip4/
|-- account/
|   |-- migrations/
|   |   `-- __init__.py
|   |-- templates/
|   |   |-- home.html
|   |   |-- login.html
|   |   `-- register.html
|   |-- __init__.py
|   |-- admin.py
|   |-- apps.py
|   |-- models.py
|   |-- tests.py
|   |-- urls.py
|   `-- views.py
|-- slip4/
|   |-- __init__.py
|   |-- asgi.py
|   |-- settings.py
|   |-- urls.py
|   `-- wsgi.py
`-- manage.py

--------------------------------------------------------------------------------
FILE : settings.py
PATH : slip4/slip4/settings.py
--------------------------------------------------------------------------------
"""
Django settings for slip4 project.

Generated by 'django-admin startproject' using Django 5.2.19.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-6pzqvtwd89+a7f%b8@b7p@-*os3$&d8+#t$=winbv*(!bp=436'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'account',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'slip4.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'slip4.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/5.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.2/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

--------------------------------------------------------------------------------
FILE : models.py
PATH : slip4/account/models.py
--------------------------------------------------------------------------------
from django.db import models

# Create your models here.

--------------------------------------------------------------------------------
FILE : admin.py
PATH : slip4/account/admin.py
--------------------------------------------------------------------------------
from django.contrib import admin

# Register your models here.

--------------------------------------------------------------------------------
FILE : views.py
PATH : slip4/account/views.py
--------------------------------------------------------------------------------
from django.shortcuts import render, redirect
from django.contrib.auth.models import User


def home(request):
    return render(request, 'home.html')


def register(request):
    error = ''
    if request.method == 'POST':
        username = request.POST['username']
        email = request.POST['email']
        password = request.POST['password']
        cpassword = request.POST['cpassword']

        if password != cpassword:
            error = 'Passwords do not match.'
        elif User.objects.filter(username=username).exists():
            error = 'Username already exists.'
        else:
            User.objects.create_user(username=username, email=email, password=password)
            return redirect('login')

    return render(request, 'register.html', {'error': error})


def login_page(request):
    return render(request, 'login.html')

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip4/account/urls.py
--------------------------------------------------------------------------------
from django.urls import path
from . import views

urlpatterns = [
    path('', views.home, name='home'),
    path('register/', views.register, name='register'),
    path('login/', views.login_page, name='login'),
]

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip4/slip4/urls.py
--------------------------------------------------------------------------------
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('account.urls')),
]

--------------------------------------------------------------------------------
FILE : home.html
PATH : slip4/account/templates/home.html
--------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Home</title>
</head>
<body>
  <h1>Welcome</h1>
  <a href="{% url 'register' %}">Register</a> |
  <a href="{% url 'login' %}">Login</a>
</body>
</html>

--------------------------------------------------------------------------------
FILE : login.html
PATH : slip4/account/templates/login.html
--------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Login</title>
</head>
<body>
  <h1>Login</h1>

  {% if error %}<p style="color:red">{{ error }}</p>{% endif %}

  <form method="post">
    {% csrf_token %}
    <p>Username: <input type="text" name="username" required></p>
    <p>Password: <input type="password" name="password" required></p>
    <button type="submit">Login</button>
  </form>

  <p>New user? <a href="{% url 'register' %}">Register</a></p>
</body>
</html>

--------------------------------------------------------------------------------
FILE : register.html
PATH : slip4/account/templates/register.html
--------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Register</title>
</head>
<body>
  <h1>Register</h1>

  {% if error %}<p style="color:red">{{ error }}</p>{% endif %}

  <form method="post">
    {% csrf_token %}
    <p>Username: <input type="text" name="username" required></p>
    <p>Email: <input type="email" name="email" required></p>
    <p>Password: <input type="password" name="password" required></p>
    <p>Confirm Password: <input type="password" name="cpassword" required></p>
    <button type="submit">Register</button>
  </form>

  <p>Already registered? <a href="{% url 'login' %}">Login</a></p>
</body>
</html>

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip4/account/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : apps.py
PATH : slip4/account/apps.py
--------------------------------------------------------------------------------
from django.apps import AppConfig


class AccountConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'account'

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip4/account/migrations/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : tests.py
PATH : slip4/account/tests.py
--------------------------------------------------------------------------------
from django.test import TestCase

# Create your tests here.

--------------------------------------------------------------------------------
FILE : manage.py
PATH : slip4/manage.py
--------------------------------------------------------------------------------
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip4.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip4/slip4/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : asgi.py
PATH : slip4/slip4/asgi.py
--------------------------------------------------------------------------------
"""
ASGI config for slip4 project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip4.settings')

application = get_asgi_application()

--------------------------------------------------------------------------------
FILE : wsgi.py
PATH : slip4/slip4/wsgi.py
--------------------------------------------------------------------------------
"""
WSGI config for slip4 project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip4.settings')

application = get_wsgi_application()

################################################################################
# SLIP 5 : Static images in a dashboard
################################################################################

QUESTION

Time: 3 hours | Marks: 25

1. Create a new Django project and a simple dashboard app and register it in settings.py. Configure the static folder. Add a few dummy images into the static directory. [10]
2. Display the static images in the dashboard page using the static concept. [10]
3. Viva [5]

FOLDER STRUCTURE

slip5/
|-- dashboard/
|   |-- migrations/
|   |   `-- __init__.py
|   |-- templates/
|   |   `-- dashboard.html
|   |-- __init__.py
|   |-- admin.py
|   |-- apps.py
|   |-- models.py
|   |-- tests.py
|   |-- urls.py
|   `-- views.py
|-- slip5/
|   |-- __init__.py
|   |-- asgi.py
|   |-- settings.py
|   |-- urls.py
|   `-- wsgi.py
|-- static/
|   `-- images/
|       |-- photo1.jpg
|       `-- photo2.jpg
`-- manage.py

--------------------------------------------------------------------------------
FILE : settings.py
PATH : slip5/slip5/settings.py
--------------------------------------------------------------------------------
"""
Django settings for slip5 project.

Generated by 'django-admin startproject' using Django 5.2.19.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-zvc04g2w5k&yg*948oiim745y&lbnvdp4(83mjd&ci00#y6da7'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'dashboard',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'slip5.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'slip5.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/5.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.2/howto/static-files/

STATIC_URL = 'static/'
STATICFILES_DIRS = [BASE_DIR / 'static']

# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

--------------------------------------------------------------------------------
FILE : models.py
PATH : slip5/dashboard/models.py
--------------------------------------------------------------------------------
from django.db import models

# Create your models here.

--------------------------------------------------------------------------------
FILE : admin.py
PATH : slip5/dashboard/admin.py
--------------------------------------------------------------------------------
from django.contrib import admin

# Register your models here.

--------------------------------------------------------------------------------
FILE : views.py
PATH : slip5/dashboard/views.py
--------------------------------------------------------------------------------
from django.shortcuts import render


def dashboard(request):
    return render(request, 'dashboard.html')

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip5/dashboard/urls.py
--------------------------------------------------------------------------------
from django.urls import path
from . import views

urlpatterns = [
    path('', views.dashboard, name='dashboard'),
]

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip5/slip5/urls.py
--------------------------------------------------------------------------------
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('dashboard.urls')),
]

--------------------------------------------------------------------------------
FILE : dashboard.html
PATH : slip5/dashboard/templates/dashboard.html
--------------------------------------------------------------------------------
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Dashboard</title>
</head>
<body>
  <h1>My Dashboard</h1>

  <img src="{% static 'images/photo1.jpg' %}" alt="First image" width="400">
  <img src="{% static 'images/photo2.jpg' %}" alt="Second image" width="400">
</body>
</html>

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip5/dashboard/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : apps.py
PATH : slip5/dashboard/apps.py
--------------------------------------------------------------------------------
from django.apps import AppConfig


class DashboardConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'dashboard'

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip5/dashboard/migrations/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : tests.py
PATH : slip5/dashboard/tests.py
--------------------------------------------------------------------------------
from django.test import TestCase

# Create your tests here.

--------------------------------------------------------------------------------
FILE : photo1.jpg
PATH : slip5/static/images/photo1.jpg
--------------------------------------------------------------------------------
(image file, not shown as text. Use: dpythons get 5)

--------------------------------------------------------------------------------
FILE : photo2.jpg
PATH : slip5/static/images/photo2.jpg
--------------------------------------------------------------------------------
(image file, not shown as text. Use: dpythons get 5)

--------------------------------------------------------------------------------
FILE : manage.py
PATH : slip5/manage.py
--------------------------------------------------------------------------------
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip5.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip5/slip5/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : asgi.py
PATH : slip5/slip5/asgi.py
--------------------------------------------------------------------------------
"""
ASGI config for slip5 project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip5.settings')

application = get_asgi_application()

--------------------------------------------------------------------------------
FILE : wsgi.py
PATH : slip5/slip5/wsgi.py
--------------------------------------------------------------------------------
"""
WSGI config for slip5 project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip5.settings')

application = get_wsgi_application()

################################################################################
# SLIP 6 : Header, footer and Bootstrap navbar
################################################################################

QUESTION

Time: 3 hours | Marks: 25

1. Create a new Django project and implement base.html. Follow the Django template structure and create header and footer in base.html. [10]
2. Using {% block content %}{% endblock %} implement "home, admissions, news" menus using a Bootstrap navbar. Use the url concept of Django. Each menu link should be clickable. [10]
3. Viva [5]

FOLDER STRUCTURE

slip6/
|-- pages/
|   |-- migrations/
|   |   `-- __init__.py
|   |-- __init__.py
|   |-- admin.py
|   |-- apps.py
|   |-- models.py
|   |-- tests.py
|   |-- urls.py
|   `-- views.py
|-- slip6/
|   |-- __init__.py
|   |-- asgi.py
|   |-- settings.py
|   |-- urls.py
|   `-- wsgi.py
|-- templates/
|   |-- pages/
|   |   |-- admissions.html
|   |   |-- home.html
|   |   `-- news.html
|   `-- base.html
`-- manage.py

--------------------------------------------------------------------------------
FILE : settings.py
PATH : slip6/slip6/settings.py
--------------------------------------------------------------------------------
"""
Django settings for slip6 project.

Generated by 'django-admin startproject' using Django 5.2.19.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-zqzx#9h4rv!*c%!(!hzd1mv2r0gwive1zl=4gs=p%h0re1@#-8'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'pages',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'slip6.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR / 'templates'],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'slip6.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/5.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.2/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

--------------------------------------------------------------------------------
FILE : models.py
PATH : slip6/pages/models.py
--------------------------------------------------------------------------------
from django.db import models

# Create your models here.

--------------------------------------------------------------------------------
FILE : admin.py
PATH : slip6/pages/admin.py
--------------------------------------------------------------------------------
from django.contrib import admin

# Register your models here.

--------------------------------------------------------------------------------
FILE : views.py
PATH : slip6/pages/views.py
--------------------------------------------------------------------------------
from django.shortcuts import render


def home(request):
    return render(request, 'pages/home.html')


def admissions(request):
    return render(request, 'pages/admissions.html')


def news(request):
    return render(request, 'pages/news.html')

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip6/pages/urls.py
--------------------------------------------------------------------------------
from django.urls import path
from . import views

urlpatterns = [
    path('', views.home, name='home'),
    path('admissions/', views.admissions, name='admissions'),
    path('news/', views.news, name='news'),
]

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip6/slip6/urls.py
--------------------------------------------------------------------------------
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('pages.urls')),
]

--------------------------------------------------------------------------------
FILE : base.html
PATH : slip6/templates/base.html
--------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>{% block title %}My College{% endblock %}</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
  <header class="container py-3">
    <h2>My College</h2>
  </header>

  <nav class="navbar navbar-expand navbar-dark bg-dark">
    <div class="container">
      <div class="navbar-nav">
        <a class="nav-link" href="{% url 'home' %}">Home</a>
        <a class="nav-link" href="{% url 'admissions' %}">Admissions</a>
        <a class="nav-link" href="{% url 'news' %}">News</a>
      </div>
    </div>
  </nav>

  <main class="container py-4">
    {% block content %}
    {% endblock %}
  </main>

  <footer class="container border-top py-3">
    <p>&copy; 2026 My College</p>
  </footer>
</body>
</html>

--------------------------------------------------------------------------------
FILE : admissions.html
PATH : slip6/templates/pages/admissions.html
--------------------------------------------------------------------------------
{% extends 'base.html' %}

{% block title %}Admissions{% endblock %}

{% block content %}
  <h1>I am in admissions</h1>
{% endblock %}

--------------------------------------------------------------------------------
FILE : home.html
PATH : slip6/templates/pages/home.html
--------------------------------------------------------------------------------
{% extends 'base.html' %}

{% block title %}Home{% endblock %}

{% block content %}
  <h1>I am in home</h1>
{% endblock %}

--------------------------------------------------------------------------------
FILE : news.html
PATH : slip6/templates/pages/news.html
--------------------------------------------------------------------------------
{% extends 'base.html' %}

{% block title %}News{% endblock %}

{% block content %}
  <h1>I am in news</h1>
{% endblock %}

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip6/pages/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : apps.py
PATH : slip6/pages/apps.py
--------------------------------------------------------------------------------
from django.apps import AppConfig


class PagesConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'pages'

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip6/pages/migrations/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : tests.py
PATH : slip6/pages/tests.py
--------------------------------------------------------------------------------
from django.test import TestCase

# Create your tests here.

--------------------------------------------------------------------------------
FILE : manage.py
PATH : slip6/manage.py
--------------------------------------------------------------------------------
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip6.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip6/slip6/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : asgi.py
PATH : slip6/slip6/asgi.py
--------------------------------------------------------------------------------
"""
ASGI config for slip6 project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip6.settings')

application = get_asgi_application()

--------------------------------------------------------------------------------
FILE : wsgi.py
PATH : slip6/slip6/wsgi.py
--------------------------------------------------------------------------------
"""
WSGI config for slip6 project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip6.settings')

application = get_wsgi_application()

################################################################################
# SLIP 7 : DRF Message list API
################################################################################

QUESTION

Time: 3 hours | Marks: 25

1. Create a django project using the admin command. Enable rest_framework, set DRF configuration. Create a model Message with attributes content, sender and date. Perform migration. [10]
2. Create a rest_demo application and register it. Expose a (GET) ListAPIView API which returns all Messages from the DB. (Insert dummy messages through the Admin Panel.) [10]
3. Viva [5]

FOLDER STRUCTURE

slip7/
|-- rest_demo/
|   |-- migrations/
|   |   |-- 0001_initial.py
|   |   `-- __init__.py
|   |-- __init__.py
|   |-- admin.py
|   |-- apps.py
|   |-- models.py
|   |-- serializers.py
|   |-- tests.py
|   |-- urls.py
|   `-- views.py
|-- slip7/
|   |-- __init__.py
|   |-- asgi.py
|   |-- settings.py
|   |-- urls.py
|   `-- wsgi.py
`-- manage.py

--------------------------------------------------------------------------------
FILE : settings.py
PATH : slip7/slip7/settings.py
--------------------------------------------------------------------------------
"""
Django settings for slip7 project.

Generated by 'django-admin startproject' using Django 5.2.19.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-y(nsyjahw(f6n38)rz2jn1h%n8)o^0@smyv=49v^!rzv81d=vb'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'rest_demo',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'slip7.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'slip7.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/5.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.2/howto/static-files/

STATIC_URL = 'static/'

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.AllowAny',
    ],
    'DEFAULT_RENDERER_CLASSES': [
        'rest_framework.renderers.JSONRenderer',
        'rest_framework.renderers.BrowsableAPIRenderer',
    ],
}

# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

--------------------------------------------------------------------------------
FILE : models.py
PATH : slip7/rest_demo/models.py
--------------------------------------------------------------------------------
from django.db import models


class Message(models.Model):
    content = models.TextField()
    sender = models.CharField(max_length=100)
    date = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return f'{self.sender}: {self.content[:30]}'

--------------------------------------------------------------------------------
FILE : admin.py
PATH : slip7/rest_demo/admin.py
--------------------------------------------------------------------------------
from django.contrib import admin
from .models import Message

admin.site.register(Message)

--------------------------------------------------------------------------------
FILE : serializers.py
PATH : slip7/rest_demo/serializers.py
--------------------------------------------------------------------------------
from rest_framework import serializers
from .models import Message


class MessageSerializer(serializers.ModelSerializer):
    class Meta:
        model = Message
        fields = '__all__'

--------------------------------------------------------------------------------
FILE : views.py
PATH : slip7/rest_demo/views.py
--------------------------------------------------------------------------------
from rest_framework.generics import ListAPIView
from .models import Message
from .serializers import MessageSerializer


class MessageListView(ListAPIView):
    queryset = Message.objects.all()
    serializer_class = MessageSerializer

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip7/rest_demo/urls.py
--------------------------------------------------------------------------------
from django.urls import path
from .views import MessageListView

urlpatterns = [
    path('messages/', MessageListView.as_view(), name='message-list'),
]

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip7/slip7/urls.py
--------------------------------------------------------------------------------
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/', include('rest_demo.urls')),
]

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip7/rest_demo/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : apps.py
PATH : slip7/rest_demo/apps.py
--------------------------------------------------------------------------------
from django.apps import AppConfig


class RestDemoConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'rest_demo'

--------------------------------------------------------------------------------
FILE : 0001_initial.py
PATH : slip7/rest_demo/migrations/0001_initial.py
--------------------------------------------------------------------------------
# Generated by Django 5.2.19 on 2026-11-25 17:54

from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Message',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('content', models.TextField()),
                ('sender', models.CharField(max_length=100)),
                ('date', models.DateTimeField(auto_now_add=True)),
            ],
        ),
    ]

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip7/rest_demo/migrations/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : tests.py
PATH : slip7/rest_demo/tests.py
--------------------------------------------------------------------------------
from django.test import TestCase

# Create your tests here.

--------------------------------------------------------------------------------
FILE : manage.py
PATH : slip7/manage.py
--------------------------------------------------------------------------------
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip7.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip7/slip7/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : asgi.py
PATH : slip7/slip7/asgi.py
--------------------------------------------------------------------------------
"""
ASGI config for slip7 project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip7.settings')

application = get_asgi_application()

--------------------------------------------------------------------------------
FILE : wsgi.py
PATH : slip7/slip7/wsgi.py
--------------------------------------------------------------------------------
"""
WSGI config for slip7 project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip7.settings')

application = get_wsgi_application()

################################################################################
# SLIP 8 : Student model and list page
################################################################################

QUESTION

Time: 3 hours | Marks: 25

1. Configure mysql/sqlite DB in a newly created project. Create a model of Student table having attributes name, address and age. Perform migration. [10]
2. Create superuser via admin command and login to the admin panel. Verify whether the table has been created. Also list the Students data from DB on a Django HTML page. [10]
3. Viva [5]

FOLDER STRUCTURE

slip8/
|-- slip8/
|   |-- __init__.py
|   |-- asgi.py
|   |-- settings.py
|   |-- urls.py
|   `-- wsgi.py
|-- students/
|   |-- migrations/
|   |   |-- 0001_initial.py
|   |   `-- __init__.py
|   |-- templates/
|   |   `-- students.html
|   |-- __init__.py
|   |-- admin.py
|   |-- apps.py
|   |-- models.py
|   |-- tests.py
|   |-- urls.py
|   `-- views.py
`-- manage.py

--------------------------------------------------------------------------------
FILE : settings.py
PATH : slip8/slip8/settings.py
--------------------------------------------------------------------------------
"""
Django settings for slip8 project.

Generated by 'django-admin startproject' using Django 5.2.19.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-9s4fy37oe4=zop0wata=v4_4pezz_#+jeb69z1x%q!=l*fl--y'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'students',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'slip8.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'slip8.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/5.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.2/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

--------------------------------------------------------------------------------
FILE : models.py
PATH : slip8/students/models.py
--------------------------------------------------------------------------------
from django.db import models


class Student(models.Model):
    name = models.CharField(max_length=100)
    address = models.CharField(max_length=200)
    age = models.PositiveIntegerField()

    def __str__(self):
        return self.name

--------------------------------------------------------------------------------
FILE : admin.py
PATH : slip8/students/admin.py
--------------------------------------------------------------------------------
from django.contrib import admin
from .models import Student

admin.site.register(Student)

--------------------------------------------------------------------------------
FILE : views.py
PATH : slip8/students/views.py
--------------------------------------------------------------------------------
from django.shortcuts import render
from .models import Student


def student_list(request):
    students = Student.objects.all()
    return render(request, 'students.html', {'students': students})

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip8/students/urls.py
--------------------------------------------------------------------------------
from django.urls import path
from . import views

urlpatterns = [
    path('', views.student_list, name='student_list'),
]

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip8/slip8/urls.py
--------------------------------------------------------------------------------
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('students.urls')),
]

--------------------------------------------------------------------------------
FILE : students.html
PATH : slip8/students/templates/students.html
--------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Student List</title>
</head>
<body>
  <h1>Student Details</h1>

  <table border="1" cellpadding="6">
    <tr>
      <th>Name</th>
      <th>Address</th>
      <th>Age</th>
    </tr>

    {% for student in students %}
    <tr>
      <td>{{ student.name }}</td>
      <td>{{ student.address }}</td>
      <td>{{ student.age }}</td>
    </tr>
    {% empty %}
    <tr>
      <td colspan="3">No records found.</td>
    </tr>
    {% endfor %}
  </table>
</body>
</html>

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip8/students/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : apps.py
PATH : slip8/students/apps.py
--------------------------------------------------------------------------------
from django.apps import AppConfig


class StudentsConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'students'

--------------------------------------------------------------------------------
FILE : 0001_initial.py
PATH : slip8/students/migrations/0001_initial.py
--------------------------------------------------------------------------------
# Generated by Django 5.2.19 on 2026-11-25 17:54

from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Student',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=100)),
                ('address', models.CharField(max_length=200)),
                ('age', models.PositiveIntegerField()),
            ],
        ),
    ]

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip8/students/migrations/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : tests.py
PATH : slip8/students/tests.py
--------------------------------------------------------------------------------
from django.test import TestCase

# Create your tests here.

--------------------------------------------------------------------------------
FILE : manage.py
PATH : slip8/manage.py
--------------------------------------------------------------------------------
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip8.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip8/slip8/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : asgi.py
PATH : slip8/slip8/asgi.py
--------------------------------------------------------------------------------
"""
ASGI config for slip8 project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip8.settings')

application = get_asgi_application()

--------------------------------------------------------------------------------
FILE : wsgi.py
PATH : slip8/slip8/wsgi.py
--------------------------------------------------------------------------------
"""
WSGI config for slip8 project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip8.settings')

application = get_wsgi_application()

################################################################################
# SLIP 9 : Teacher model and list page
################################################################################

QUESTION

Time: 3 hours | Marks: 25

1. Configure mysql/sqlite DB in a newly created project. Create a model of Teacher table having attributes name, qualification and experience. [10]
2. Perform migration. Create superuser and login to the admin panel. Verify whether the table has been created. Retrieve Teacher data from the database and display it on the UI. [10]
3. Viva [5]

FOLDER STRUCTURE

slip9/
|-- slip9/
|   |-- __init__.py
|   |-- asgi.py
|   |-- settings.py
|   |-- urls.py
|   `-- wsgi.py
|-- teachers/
|   |-- migrations/
|   |   |-- 0001_initial.py
|   |   `-- __init__.py
|   |-- templates/
|   |   `-- teachers.html
|   |-- __init__.py
|   |-- admin.py
|   |-- apps.py
|   |-- models.py
|   |-- tests.py
|   |-- urls.py
|   `-- views.py
`-- manage.py

--------------------------------------------------------------------------------
FILE : settings.py
PATH : slip9/slip9/settings.py
--------------------------------------------------------------------------------
"""
Django settings for slip9 project.

Generated by 'django-admin startproject' using Django 5.2.19.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-66r$*4ok2v%no4wtb2^9+!(_9u=xz)1-%rp$!k#xyl!57(#_vc'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'teachers',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'slip9.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'slip9.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/5.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.2/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

--------------------------------------------------------------------------------
FILE : models.py
PATH : slip9/teachers/models.py
--------------------------------------------------------------------------------
from django.db import models


class Teacher(models.Model):
    name = models.CharField(max_length=100)
    qualification = models.CharField(max_length=100)
    experience = models.PositiveIntegerField()

    def __str__(self):
        return self.name

--------------------------------------------------------------------------------
FILE : admin.py
PATH : slip9/teachers/admin.py
--------------------------------------------------------------------------------
from django.contrib import admin
from .models import Teacher

admin.site.register(Teacher)

--------------------------------------------------------------------------------
FILE : views.py
PATH : slip9/teachers/views.py
--------------------------------------------------------------------------------
from django.shortcuts import render
from .models import Teacher


def teacher_list(request):
    teachers = Teacher.objects.all()
    return render(request, 'teachers.html', {'teachers': teachers})

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip9/teachers/urls.py
--------------------------------------------------------------------------------
from django.urls import path
from . import views

urlpatterns = [
    path('', views.teacher_list, name='teacher_list'),
]

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip9/slip9/urls.py
--------------------------------------------------------------------------------
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('teachers.urls')),
]

--------------------------------------------------------------------------------
FILE : teachers.html
PATH : slip9/teachers/templates/teachers.html
--------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Teacher List</title>
</head>
<body>
  <h1>Teacher Details</h1>

  <table border="1" cellpadding="6">
    <tr>
      <th>Name</th>
      <th>Qualification</th>
      <th>Experience (years)</th>
    </tr>

    {% for teacher in teachers %}
    <tr>
      <td>{{ teacher.name }}</td>
      <td>{{ teacher.qualification }}</td>
      <td>{{ teacher.experience }}</td>
    </tr>
    {% empty %}
    <tr>
      <td colspan="3">No records found.</td>
    </tr>
    {% endfor %}
  </table>
</body>
</html>

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip9/teachers/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : apps.py
PATH : slip9/teachers/apps.py
--------------------------------------------------------------------------------
from django.apps import AppConfig


class TeachersConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'teachers'

--------------------------------------------------------------------------------
FILE : 0001_initial.py
PATH : slip9/teachers/migrations/0001_initial.py
--------------------------------------------------------------------------------
# Generated by Django 5.2.19 on 2026-11-25 17:54

from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Teacher',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=100)),
                ('qualification', models.CharField(max_length=100)),
                ('experience', models.PositiveIntegerField()),
            ],
        ),
    ]

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip9/teachers/migrations/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : tests.py
PATH : slip9/teachers/tests.py
--------------------------------------------------------------------------------
from django.test import TestCase

# Create your tests here.

--------------------------------------------------------------------------------
FILE : manage.py
PATH : slip9/manage.py
--------------------------------------------------------------------------------
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip9.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip9/slip9/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : asgi.py
PATH : slip9/slip9/asgi.py
--------------------------------------------------------------------------------
"""
ASGI config for slip9 project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip9.settings')

application = get_asgi_application()

--------------------------------------------------------------------------------
FILE : wsgi.py
PATH : slip9/slip9/wsgi.py
--------------------------------------------------------------------------------
"""
WSGI config for slip9 project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip9.settings')

application = get_wsgi_application()

################################################################################
# SLIP 10 : Product model and admin
################################################################################

QUESTION

Time: 3 hours | Marks: 25

1. Configure mysql/sqlite DB in a newly created project. Create a model of Product table having attributes Pname, description and cost. [10]
2. Perform migration. Create superuser via admin command and login to the admin panel. Verify whether the table has been created in DB. [10]
3. Viva [5]

FOLDER STRUCTURE

slip10/
|-- products/
|   |-- migrations/
|   |   |-- 0001_initial.py
|   |   `-- __init__.py
|   |-- __init__.py
|   |-- admin.py
|   |-- apps.py
|   |-- models.py
|   |-- tests.py
|   `-- views.py
|-- slip10/
|   |-- __init__.py
|   |-- asgi.py
|   |-- settings.py
|   |-- urls.py
|   `-- wsgi.py
`-- manage.py

--------------------------------------------------------------------------------
FILE : settings.py
PATH : slip10/slip10/settings.py
--------------------------------------------------------------------------------
"""
Django settings for slip10 project.

Generated by 'django-admin startproject' using Django 5.2.19.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-@5x3byxohx$h0^y7@urpmv*z2ds9_13meh4w_lqj2^b8okpda8'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'products',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'slip10.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'slip10.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/5.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.2/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

--------------------------------------------------------------------------------
FILE : models.py
PATH : slip10/products/models.py
--------------------------------------------------------------------------------
from django.db import models


class Product(models.Model):
    Pname = models.CharField(max_length=100)
    description = models.TextField()
    cost = models.DecimalField(max_digits=10, decimal_places=2)

    def __str__(self):
        return self.Pname

--------------------------------------------------------------------------------
FILE : admin.py
PATH : slip10/products/admin.py
--------------------------------------------------------------------------------
from django.contrib import admin
from .models import Product

admin.site.register(Product)

--------------------------------------------------------------------------------
FILE : views.py
PATH : slip10/products/views.py
--------------------------------------------------------------------------------
from django.shortcuts import render

# Create your views here.

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip10/slip10/urls.py
--------------------------------------------------------------------------------
"""
URL configuration for slip10 project.

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/5.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path

urlpatterns = [
    path('admin/', admin.site.urls),
]

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip10/products/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : apps.py
PATH : slip10/products/apps.py
--------------------------------------------------------------------------------
from django.apps import AppConfig


class ProductsConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'products'

--------------------------------------------------------------------------------
FILE : 0001_initial.py
PATH : slip10/products/migrations/0001_initial.py
--------------------------------------------------------------------------------
# Generated by Django 5.2.19 on 2026-11-25 17:54

from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Product',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('Pname', models.CharField(max_length=100)),
                ('description', models.TextField()),
                ('cost', models.DecimalField(decimal_places=2, max_digits=10)),
            ],
        ),
    ]

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip10/products/migrations/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : tests.py
PATH : slip10/products/tests.py
--------------------------------------------------------------------------------
from django.test import TestCase

# Create your tests here.

--------------------------------------------------------------------------------
FILE : manage.py
PATH : slip10/manage.py
--------------------------------------------------------------------------------
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip10.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip10/slip10/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : asgi.py
PATH : slip10/slip10/asgi.py
--------------------------------------------------------------------------------
"""
ASGI config for slip10 project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip10.settings')

application = get_asgi_application()

--------------------------------------------------------------------------------
FILE : wsgi.py
PATH : slip10/slip10/wsgi.py
--------------------------------------------------------------------------------
"""
WSGI config for slip10 project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip10.settings')

application = get_wsgi_application()

################################################################################
# SLIP 11 : Account model, name and balance
################################################################################

QUESTION

Time: 3 hours | Marks: 25

1. Configure mysql/sqlite DB in a newly created project. Create a model of Account table having attributes name, number and balance. Perform migration. Create superuser, login to the admin panel and verify whether the table has been created. [10]
2. Retrieve Account details from the database and display the name and balance in an HTML page. (Insert a few dummy records via the Admin Panel.) [10]
3. Viva [5]

FOLDER STRUCTURE

slip11/
|-- accounts/
|   |-- migrations/
|   |   |-- 0001_initial.py
|   |   `-- __init__.py
|   |-- templates/
|   |   `-- accounts.html
|   |-- __init__.py
|   |-- admin.py
|   |-- apps.py
|   |-- models.py
|   |-- tests.py
|   |-- urls.py
|   `-- views.py
|-- slip11/
|   |-- __init__.py
|   |-- asgi.py
|   |-- settings.py
|   |-- urls.py
|   `-- wsgi.py
`-- manage.py

--------------------------------------------------------------------------------
FILE : settings.py
PATH : slip11/slip11/settings.py
--------------------------------------------------------------------------------
"""
Django settings for slip11 project.

Generated by 'django-admin startproject' using Django 5.2.19.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-429gl(ouc_1*6w#yno%$x_rsthli^9c5d4+&o%na*9y@p68#-q'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'accounts',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'slip11.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'slip11.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/5.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.2/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

--------------------------------------------------------------------------------
FILE : models.py
PATH : slip11/accounts/models.py
--------------------------------------------------------------------------------
from django.db import models


class Account(models.Model):
    name = models.CharField(max_length=100)
    number = models.CharField(max_length=20, unique=True)
    balance = models.DecimalField(max_digits=12, decimal_places=2)

    def __str__(self):
        return self.name

--------------------------------------------------------------------------------
FILE : admin.py
PATH : slip11/accounts/admin.py
--------------------------------------------------------------------------------
from django.contrib import admin
from .models import Account

admin.site.register(Account)

--------------------------------------------------------------------------------
FILE : views.py
PATH : slip11/accounts/views.py
--------------------------------------------------------------------------------
from django.shortcuts import render
from .models import Account


def account_list(request):
    accounts = Account.objects.all()
    return render(request, 'accounts.html', {'accounts': accounts})

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip11/accounts/urls.py
--------------------------------------------------------------------------------
from django.urls import path
from . import views

urlpatterns = [
    path('', views.account_list, name='account_list'),
]

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip11/slip11/urls.py
--------------------------------------------------------------------------------
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('accounts.urls')),
]

--------------------------------------------------------------------------------
FILE : accounts.html
PATH : slip11/accounts/templates/accounts.html
--------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Account List</title>
</head>
<body>
  <h1>Account Details</h1>

  <table border="1" cellpadding="6">
    <tr>
      <th>Name</th>
      <th>Balance</th>
    </tr>

    {% for account in accounts %}
    <tr>
      <td>{{ account.name }}</td>
      <td>{{ account.balance }}</td>
    </tr>
    {% empty %}
    <tr>
      <td colspan="2">No records found.</td>
    </tr>
    {% endfor %}
  </table>
</body>
</html>

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip11/accounts/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : apps.py
PATH : slip11/accounts/apps.py
--------------------------------------------------------------------------------
from django.apps import AppConfig


class AccountsConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'accounts'

--------------------------------------------------------------------------------
FILE : 0001_initial.py
PATH : slip11/accounts/migrations/0001_initial.py
--------------------------------------------------------------------------------
# Generated by Django 5.2.19 on 2026-11-25 17:54

from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Account',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=100)),
                ('number', models.CharField(max_length=20, unique=True)),
                ('balance', models.DecimalField(decimal_places=2, max_digits=12)),
            ],
        ),
    ]

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip11/accounts/migrations/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : tests.py
PATH : slip11/accounts/tests.py
--------------------------------------------------------------------------------
from django.test import TestCase

# Create your tests here.

--------------------------------------------------------------------------------
FILE : manage.py
PATH : slip11/manage.py
--------------------------------------------------------------------------------
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip11.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip11/slip11/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : asgi.py
PATH : slip11/slip11/asgi.py
--------------------------------------------------------------------------------
"""
ASGI config for slip11 project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip11.settings')

application = get_asgi_application()

--------------------------------------------------------------------------------
FILE : wsgi.py
PATH : slip11/slip11/wsgi.py
--------------------------------------------------------------------------------
"""
WSGI config for slip11 project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip11.settings')

application = get_wsgi_application()

################################################################################
# SLIP 12 : DRF Message list API
################################################################################

QUESTION

Time: 3 hours | Marks: 25

1. Create a django project using the admin command. Enable rest_framework, set DRF configuration. Create a simple model named Message. Perform migration. [10]
2. Create a rest_demo application and register it. Expose a (GET) ListAPIView API which returns all Messages from the DB. (Insert dummy messages through the Admin Panel.) [10]
3. Viva [5]

> Note: This slip does not give the attributes of Message. Use content, sender, date (same as slips 7 and 16) and tell the examiner you chose them.

FOLDER STRUCTURE

slip12/
|-- rest_demo/
|   |-- migrations/
|   |   |-- 0001_initial.py
|   |   `-- __init__.py
|   |-- __init__.py
|   |-- admin.py
|   |-- apps.py
|   |-- models.py
|   |-- serializers.py
|   |-- tests.py
|   |-- urls.py
|   `-- views.py
|-- slip12/
|   |-- __init__.py
|   |-- asgi.py
|   |-- settings.py
|   |-- urls.py
|   `-- wsgi.py
`-- manage.py

--------------------------------------------------------------------------------
FILE : settings.py
PATH : slip12/slip12/settings.py
--------------------------------------------------------------------------------
"""
Django settings for slip12 project.

Generated by 'django-admin startproject' using Django 5.2.19.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-_%*rw_!sk*o#hjzhs61bz4=vi1o0@lf!2xz+&3(q0r7q64vl_9'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'rest_demo',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'slip12.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'slip12.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/5.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.2/howto/static-files/

STATIC_URL = 'static/'

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.AllowAny',
    ],
    'DEFAULT_RENDERER_CLASSES': [
        'rest_framework.renderers.JSONRenderer',
        'rest_framework.renderers.BrowsableAPIRenderer',
    ],
}

# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

--------------------------------------------------------------------------------
FILE : models.py
PATH : slip12/rest_demo/models.py
--------------------------------------------------------------------------------
from django.db import models


class Message(models.Model):
    content = models.TextField()
    sender = models.CharField(max_length=100)
    date = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return f'{self.sender}: {self.content[:30]}'

--------------------------------------------------------------------------------
FILE : admin.py
PATH : slip12/rest_demo/admin.py
--------------------------------------------------------------------------------
from django.contrib import admin
from .models import Message

admin.site.register(Message)

--------------------------------------------------------------------------------
FILE : serializers.py
PATH : slip12/rest_demo/serializers.py
--------------------------------------------------------------------------------
from rest_framework import serializers
from .models import Message


class MessageSerializer(serializers.ModelSerializer):
    class Meta:
        model = Message
        fields = '__all__'

--------------------------------------------------------------------------------
FILE : views.py
PATH : slip12/rest_demo/views.py
--------------------------------------------------------------------------------
from rest_framework.generics import ListAPIView
from .models import Message
from .serializers import MessageSerializer


class MessageListView(ListAPIView):
    queryset = Message.objects.all()
    serializer_class = MessageSerializer

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip12/rest_demo/urls.py
--------------------------------------------------------------------------------
from django.urls import path
from .views import MessageListView

urlpatterns = [
    path('messages/', MessageListView.as_view(), name='message-list'),
]

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip12/slip12/urls.py
--------------------------------------------------------------------------------
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/', include('rest_demo.urls')),
]

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip12/rest_demo/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : apps.py
PATH : slip12/rest_demo/apps.py
--------------------------------------------------------------------------------
from django.apps import AppConfig


class RestDemoConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'rest_demo'

--------------------------------------------------------------------------------
FILE : 0001_initial.py
PATH : slip12/rest_demo/migrations/0001_initial.py
--------------------------------------------------------------------------------
# Generated by Django 5.2.19 on 2026-11-25 17:54

from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Message',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('content', models.TextField()),
                ('sender', models.CharField(max_length=100)),
                ('date', models.DateTimeField(auto_now_add=True)),
            ],
        ),
    ]

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip12/rest_demo/migrations/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : tests.py
PATH : slip12/rest_demo/tests.py
--------------------------------------------------------------------------------
from django.test import TestCase

# Create your tests here.

--------------------------------------------------------------------------------
FILE : manage.py
PATH : slip12/manage.py
--------------------------------------------------------------------------------
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip12.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip12/slip12/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : asgi.py
PATH : slip12/slip12/asgi.py
--------------------------------------------------------------------------------
"""
ASGI config for slip12 project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip12.settings')

application = get_asgi_application()

--------------------------------------------------------------------------------
FILE : wsgi.py
PATH : slip12/slip12/wsgi.py
--------------------------------------------------------------------------------
"""
WSGI config for slip12 project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip12.settings')

application = get_wsgi_application()

################################################################################
# SLIP 13 : Home link to product list
################################################################################

QUESTION

Time: 3 hours | Marks: 25

1. Create a django project using the admin command. Create and register a products app with a view_products page. The home page should have a link to the view_products page. [10]
2. Create a Model in products with attributes product_model, product_name. Perform migration. In the view_products page retrieve the data from SQLite DB and display it. [10]
3. Viva [5]

FOLDER STRUCTURE

slip13/
|-- products/
|   |-- migrations/
|   |   |-- 0001_initial.py
|   |   `-- __init__.py
|   |-- templates/
|   |   |-- home.html
|   |   `-- view_products.html
|   |-- __init__.py
|   |-- admin.py
|   |-- apps.py
|   |-- models.py
|   |-- tests.py
|   |-- urls.py
|   `-- views.py
|-- slip13/
|   |-- __init__.py
|   |-- asgi.py
|   |-- settings.py
|   |-- urls.py
|   `-- wsgi.py
`-- manage.py

--------------------------------------------------------------------------------
FILE : settings.py
PATH : slip13/slip13/settings.py
--------------------------------------------------------------------------------
"""
Django settings for slip13 project.

Generated by 'django-admin startproject' using Django 5.2.19.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-t3i$9-@&#+$dwc$m11pf75dxvt+(t(c)%3($hbj&7@xit@8_9s'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'products',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'slip13.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'slip13.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/5.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.2/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

--------------------------------------------------------------------------------
FILE : models.py
PATH : slip13/products/models.py
--------------------------------------------------------------------------------
from django.db import models


class Product(models.Model):
    product_model = models.CharField(max_length=100)
    product_name = models.CharField(max_length=100)

    def __str__(self):
        return self.product_name

--------------------------------------------------------------------------------
FILE : admin.py
PATH : slip13/products/admin.py
--------------------------------------------------------------------------------
from django.contrib import admin
from .models import Product

admin.site.register(Product)

--------------------------------------------------------------------------------
FILE : views.py
PATH : slip13/products/views.py
--------------------------------------------------------------------------------
from django.shortcuts import render
from .models import Product


def home(request):
    return render(request, 'home.html')


def view_products(request):
    products = Product.objects.all()
    return render(request, 'view_products.html', {'products': products})

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip13/products/urls.py
--------------------------------------------------------------------------------
from django.urls import path
from . import views

urlpatterns = [
    path('', views.home, name='home'),
    path('view_products/', views.view_products, name='view_products'),
]

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip13/slip13/urls.py
--------------------------------------------------------------------------------
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('products.urls')),
]

--------------------------------------------------------------------------------
FILE : home.html
PATH : slip13/products/templates/home.html
--------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Home</title>
</head>
<body>
  <h1>Welcome to Home</h1>
  <a href="{% url 'view_products' %}">View Products</a>
</body>
</html>

--------------------------------------------------------------------------------
FILE : view_products.html
PATH : slip13/products/templates/view_products.html
--------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Product List</title>
</head>
<body>
  <h1>Product Details</h1>

  <table border="1" cellpadding="6">
    <tr>
      <th>Product Model</th>
      <th>Product Name</th>
    </tr>

    {% for product in products %}
    <tr>
      <td>{{ product.product_model }}</td>
      <td>{{ product.product_name }}</td>
    </tr>
    {% empty %}
    <tr>
      <td colspan="2">No records found.</td>
    </tr>
    {% endfor %}
  </table>

  <p><a href="{% url 'home' %}">Back to Home</a></p>
</body>
</html>

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip13/products/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : apps.py
PATH : slip13/products/apps.py
--------------------------------------------------------------------------------
from django.apps import AppConfig


class ProductsConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'products'

--------------------------------------------------------------------------------
FILE : 0001_initial.py
PATH : slip13/products/migrations/0001_initial.py
--------------------------------------------------------------------------------
# Generated by Django 5.2.19 on 2026-11-25 17:54

from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Product',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('product_model', models.CharField(max_length=100)),
                ('product_name', models.CharField(max_length=100)),
            ],
        ),
    ]

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip13/products/migrations/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : tests.py
PATH : slip13/products/tests.py
--------------------------------------------------------------------------------
from django.test import TestCase

# Create your tests here.

--------------------------------------------------------------------------------
FILE : manage.py
PATH : slip13/manage.py
--------------------------------------------------------------------------------
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip13.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip13/slip13/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : asgi.py
PATH : slip13/slip13/asgi.py
--------------------------------------------------------------------------------
"""
ASGI config for slip13 project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip13.settings')

application = get_asgi_application()

--------------------------------------------------------------------------------
FILE : wsgi.py
PATH : slip13/slip13/wsgi.py
--------------------------------------------------------------------------------
"""
WSGI config for slip13 project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip13.settings')

application = get_wsgi_application()

################################################################################
# SLIP 14 : Student model and list page
################################################################################

QUESTION

Time: 3 hours | Marks: 25

1. Configure mysql/sqlite DB in a newly created project. Create a model of Student table having attributes name, address and age. Perform migration. [10]
2. Create superuser via admin command and login to the admin panel. Verify whether the table has been created. Also retrieve the student's data from DB and display it on an HTML page. [10]
3. Viva [5]

FOLDER STRUCTURE

slip14/
|-- slip14/
|   |-- __init__.py
|   |-- asgi.py
|   |-- settings.py
|   |-- urls.py
|   `-- wsgi.py
|-- students/
|   |-- migrations/
|   |   |-- 0001_initial.py
|   |   `-- __init__.py
|   |-- templates/
|   |   `-- students.html
|   |-- __init__.py
|   |-- admin.py
|   |-- apps.py
|   |-- models.py
|   |-- tests.py
|   |-- urls.py
|   `-- views.py
`-- manage.py

--------------------------------------------------------------------------------
FILE : settings.py
PATH : slip14/slip14/settings.py
--------------------------------------------------------------------------------
"""
Django settings for slip14 project.

Generated by 'django-admin startproject' using Django 5.2.19.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-j7_+j6-4-0#t_=rhmx_tq1novfwpp-i2&2t^=%of71oia&$w17'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'students',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'slip14.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'slip14.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/5.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.2/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

--------------------------------------------------------------------------------
FILE : models.py
PATH : slip14/students/models.py
--------------------------------------------------------------------------------
from django.db import models


class Student(models.Model):
    name = models.CharField(max_length=100)
    address = models.CharField(max_length=200)
    age = models.PositiveIntegerField()

    def __str__(self):
        return self.name

--------------------------------------------------------------------------------
FILE : admin.py
PATH : slip14/students/admin.py
--------------------------------------------------------------------------------
from django.contrib import admin
from .models import Student

admin.site.register(Student)

--------------------------------------------------------------------------------
FILE : views.py
PATH : slip14/students/views.py
--------------------------------------------------------------------------------
from django.shortcuts import render
from .models import Student


def student_list(request):
    students = Student.objects.all()
    return render(request, 'students.html', {'students': students})

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip14/students/urls.py
--------------------------------------------------------------------------------
from django.urls import path
from . import views

urlpatterns = [
    path('', views.student_list, name='student_list'),
]

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip14/slip14/urls.py
--------------------------------------------------------------------------------
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('students.urls')),
]

--------------------------------------------------------------------------------
FILE : students.html
PATH : slip14/students/templates/students.html
--------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Student List</title>
</head>
<body>
  <h1>Student Details</h1>

  <table border="1" cellpadding="6">
    <tr>
      <th>Name</th>
      <th>Address</th>
      <th>Age</th>
    </tr>

    {% for student in students %}
    <tr>
      <td>{{ student.name }}</td>
      <td>{{ student.address }}</td>
      <td>{{ student.age }}</td>
    </tr>
    {% empty %}
    <tr>
      <td colspan="3">No records found.</td>
    </tr>
    {% endfor %}
  </table>
</body>
</html>

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip14/students/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : apps.py
PATH : slip14/students/apps.py
--------------------------------------------------------------------------------
from django.apps import AppConfig


class StudentsConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'students'

--------------------------------------------------------------------------------
FILE : 0001_initial.py
PATH : slip14/students/migrations/0001_initial.py
--------------------------------------------------------------------------------
# Generated by Django 5.2.19 on 2026-11-25 17:54

from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Student',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=100)),
                ('address', models.CharField(max_length=200)),
                ('age', models.PositiveIntegerField()),
            ],
        ),
    ]

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip14/students/migrations/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : tests.py
PATH : slip14/students/tests.py
--------------------------------------------------------------------------------
from django.test import TestCase

# Create your tests here.

--------------------------------------------------------------------------------
FILE : manage.py
PATH : slip14/manage.py
--------------------------------------------------------------------------------
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip14.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip14/slip14/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : asgi.py
PATH : slip14/slip14/asgi.py
--------------------------------------------------------------------------------
"""
ASGI config for slip14 project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip14.settings')

application = get_asgi_application()

--------------------------------------------------------------------------------
FILE : wsgi.py
PATH : slip14/slip14/wsgi.py
--------------------------------------------------------------------------------
"""
WSGI config for slip14 project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip14.settings')

application = get_wsgi_application()

################################################################################
# SLIP 15 : Account model, name and balance
################################################################################

QUESTION

Time: 3 hours | Marks: 25

1. Configure mysql/sqlite DB in a newly created project. Create a model of Account table having attributes name, number and balance. Perform migration. Create superuser, login to the admin panel and verify whether the table has been created. [10]
2. Retrieve Account details from the database and display the name and balance in an HTML page. (Insert a few dummy records via the Admin Panel.) [10]
3. Viva [5]

FOLDER STRUCTURE

slip15/
|-- accounts/
|   |-- migrations/
|   |   |-- 0001_initial.py
|   |   `-- __init__.py
|   |-- templates/
|   |   `-- accounts.html
|   |-- __init__.py
|   |-- admin.py
|   |-- apps.py
|   |-- models.py
|   |-- tests.py
|   |-- urls.py
|   `-- views.py
|-- slip15/
|   |-- __init__.py
|   |-- asgi.py
|   |-- settings.py
|   |-- urls.py
|   `-- wsgi.py
`-- manage.py

--------------------------------------------------------------------------------
FILE : settings.py
PATH : slip15/slip15/settings.py
--------------------------------------------------------------------------------
"""
Django settings for slip15 project.

Generated by 'django-admin startproject' using Django 5.2.19.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-8^$2r8!%pltp^9-8e8+=gxndw)z)+l7xg_!dbeq^=x^19^$m1m'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'accounts',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'slip15.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'slip15.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/5.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.2/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

--------------------------------------------------------------------------------
FILE : models.py
PATH : slip15/accounts/models.py
--------------------------------------------------------------------------------
from django.db import models


class Account(models.Model):
    name = models.CharField(max_length=100)
    number = models.CharField(max_length=20, unique=True)
    balance = models.DecimalField(max_digits=12, decimal_places=2)

    def __str__(self):
        return self.name

--------------------------------------------------------------------------------
FILE : admin.py
PATH : slip15/accounts/admin.py
--------------------------------------------------------------------------------
from django.contrib import admin
from .models import Account

admin.site.register(Account)

--------------------------------------------------------------------------------
FILE : views.py
PATH : slip15/accounts/views.py
--------------------------------------------------------------------------------
from django.shortcuts import render
from .models import Account


def account_list(request):
    accounts = Account.objects.all()
    return render(request, 'accounts.html', {'accounts': accounts})

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip15/accounts/urls.py
--------------------------------------------------------------------------------
from django.urls import path
from . import views

urlpatterns = [
    path('', views.account_list, name='account_list'),
]

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip15/slip15/urls.py
--------------------------------------------------------------------------------
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('accounts.urls')),
]

--------------------------------------------------------------------------------
FILE : accounts.html
PATH : slip15/accounts/templates/accounts.html
--------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Account List</title>
</head>
<body>
  <h1>Account Details</h1>

  <table border="1" cellpadding="6">
    <tr>
      <th>Name</th>
      <th>Balance</th>
    </tr>

    {% for account in accounts %}
    <tr>
      <td>{{ account.name }}</td>
      <td>{{ account.balance }}</td>
    </tr>
    {% empty %}
    <tr>
      <td colspan="2">No records found.</td>
    </tr>
    {% endfor %}
  </table>
</body>
</html>

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip15/accounts/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : apps.py
PATH : slip15/accounts/apps.py
--------------------------------------------------------------------------------
from django.apps import AppConfig


class AccountsConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'accounts'

--------------------------------------------------------------------------------
FILE : 0001_initial.py
PATH : slip15/accounts/migrations/0001_initial.py
--------------------------------------------------------------------------------
# Generated by Django 5.2.19 on 2026-11-25 17:54

from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Account',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=100)),
                ('number', models.CharField(max_length=20, unique=True)),
                ('balance', models.DecimalField(decimal_places=2, max_digits=12)),
            ],
        ),
    ]

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip15/accounts/migrations/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : tests.py
PATH : slip15/accounts/tests.py
--------------------------------------------------------------------------------
from django.test import TestCase

# Create your tests here.

--------------------------------------------------------------------------------
FILE : manage.py
PATH : slip15/manage.py
--------------------------------------------------------------------------------
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip15.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip15/slip15/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : asgi.py
PATH : slip15/slip15/asgi.py
--------------------------------------------------------------------------------
"""
ASGI config for slip15 project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip15.settings')

application = get_asgi_application()

--------------------------------------------------------------------------------
FILE : wsgi.py
PATH : slip15/slip15/wsgi.py
--------------------------------------------------------------------------------
"""
WSGI config for slip15 project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip15.settings')

application = get_wsgi_application()

################################################################################
# SLIP 16 : DRF Message list API
################################################################################

QUESTION

Time: 3 hours | Marks: 25

1. Create a django project using the admin command. Enable rest_framework, set DRF configuration. Create a model Message with attributes content, sender and date. Perform migration. [10]
2. Create a rest_demo application and register it. Expose a (GET) ListAPIView API which returns all Messages from the DB. (Insert dummy messages through the Admin Panel.) [10]
3. Viva [5]

FOLDER STRUCTURE

slip16/
|-- rest_demo/
|   |-- migrations/
|   |   |-- 0001_initial.py
|   |   `-- __init__.py
|   |-- __init__.py
|   |-- admin.py
|   |-- apps.py
|   |-- models.py
|   |-- serializers.py
|   |-- tests.py
|   |-- urls.py
|   `-- views.py
|-- slip16/
|   |-- __init__.py
|   |-- asgi.py
|   |-- settings.py
|   |-- urls.py
|   `-- wsgi.py
`-- manage.py

--------------------------------------------------------------------------------
FILE : settings.py
PATH : slip16/slip16/settings.py
--------------------------------------------------------------------------------
"""
Django settings for slip16 project.

Generated by 'django-admin startproject' using Django 5.2.19.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-)g90zc&to&osidm)zc7m@z)g%8t!8t0$i$h4$qdlv42l^@lker'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'rest_demo',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'slip16.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'slip16.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/5.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.2/howto/static-files/

STATIC_URL = 'static/'

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.AllowAny',
    ],
    'DEFAULT_RENDERER_CLASSES': [
        'rest_framework.renderers.JSONRenderer',
        'rest_framework.renderers.BrowsableAPIRenderer',
    ],
}

# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

--------------------------------------------------------------------------------
FILE : models.py
PATH : slip16/rest_demo/models.py
--------------------------------------------------------------------------------
from django.db import models


class Message(models.Model):
    content = models.TextField()
    sender = models.CharField(max_length=100)
    date = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return f'{self.sender}: {self.content[:30]}'

--------------------------------------------------------------------------------
FILE : admin.py
PATH : slip16/rest_demo/admin.py
--------------------------------------------------------------------------------
from django.contrib import admin
from .models import Message

admin.site.register(Message)

--------------------------------------------------------------------------------
FILE : serializers.py
PATH : slip16/rest_demo/serializers.py
--------------------------------------------------------------------------------
from rest_framework import serializers
from .models import Message


class MessageSerializer(serializers.ModelSerializer):
    class Meta:
        model = Message
        fields = '__all__'

--------------------------------------------------------------------------------
FILE : views.py
PATH : slip16/rest_demo/views.py
--------------------------------------------------------------------------------
from rest_framework.generics import ListAPIView
from .models import Message
from .serializers import MessageSerializer


class MessageListView(ListAPIView):
    queryset = Message.objects.all()
    serializer_class = MessageSerializer

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip16/rest_demo/urls.py
--------------------------------------------------------------------------------
from django.urls import path
from .views import MessageListView

urlpatterns = [
    path('messages/', MessageListView.as_view(), name='message-list'),
]

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip16/slip16/urls.py
--------------------------------------------------------------------------------
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/', include('rest_demo.urls')),
]

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip16/rest_demo/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : apps.py
PATH : slip16/rest_demo/apps.py
--------------------------------------------------------------------------------
from django.apps import AppConfig


class RestDemoConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'rest_demo'

--------------------------------------------------------------------------------
FILE : 0001_initial.py
PATH : slip16/rest_demo/migrations/0001_initial.py
--------------------------------------------------------------------------------
# Generated by Django 5.2.19 on 2026-11-25 17:54

from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Message',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('content', models.TextField()),
                ('sender', models.CharField(max_length=100)),
                ('date', models.DateTimeField(auto_now_add=True)),
            ],
        ),
    ]

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip16/rest_demo/migrations/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : tests.py
PATH : slip16/rest_demo/tests.py
--------------------------------------------------------------------------------
from django.test import TestCase

# Create your tests here.

--------------------------------------------------------------------------------
FILE : manage.py
PATH : slip16/manage.py
--------------------------------------------------------------------------------
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip16.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip16/slip16/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : asgi.py
PATH : slip16/slip16/asgi.py
--------------------------------------------------------------------------------
"""
ASGI config for slip16 project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip16.settings')

application = get_asgi_application()

--------------------------------------------------------------------------------
FILE : wsgi.py
PATH : slip16/slip16/wsgi.py
--------------------------------------------------------------------------------
"""
WSGI config for slip16 project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip16.settings')

application = get_wsgi_application()

################################################################################
# SLIP 17 : User registration
################################################################################

QUESTION

Time: 3 hours | Marks: 25

1. Create a new Django project. Change the default view of the project and display login and register hyperlinks. Create a "Register form" using simple HTML tags. [10]
2. Implement code to register/insert user details into SQLite DB and on successful registration display the login page. [10]
3. Viva [5]

FOLDER STRUCTURE

slip17/
|-- account/
|   |-- migrations/
|   |   `-- __init__.py
|   |-- templates/
|   |   |-- home.html
|   |   |-- login.html
|   |   `-- register.html
|   |-- __init__.py
|   |-- admin.py
|   |-- apps.py
|   |-- models.py
|   |-- tests.py
|   |-- urls.py
|   `-- views.py
|-- slip17/
|   |-- __init__.py
|   |-- asgi.py
|   |-- settings.py
|   |-- urls.py
|   `-- wsgi.py
`-- manage.py

--------------------------------------------------------------------------------
FILE : settings.py
PATH : slip17/slip17/settings.py
--------------------------------------------------------------------------------
"""
Django settings for slip17 project.

Generated by 'django-admin startproject' using Django 5.2.19.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-zw!$kz_xhuf9*cndecft=gn4z_umw39hi*ii5gkk6pgbm24+pr'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'account',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'slip17.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'slip17.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/5.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.2/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

--------------------------------------------------------------------------------
FILE : models.py
PATH : slip17/account/models.py
--------------------------------------------------------------------------------
from django.db import models

# Create your models here.

--------------------------------------------------------------------------------
FILE : admin.py
PATH : slip17/account/admin.py
--------------------------------------------------------------------------------
from django.contrib import admin

# Register your models here.

--------------------------------------------------------------------------------
FILE : views.py
PATH : slip17/account/views.py
--------------------------------------------------------------------------------
from django.shortcuts import render, redirect
from django.contrib.auth.models import User


def home(request):
    return render(request, 'home.html')


def register(request):
    error = ''
    if request.method == 'POST':
        username = request.POST['username']
        email = request.POST['email']
        password = request.POST['password']
        cpassword = request.POST['cpassword']

        if password != cpassword:
            error = 'Passwords do not match.'
        elif User.objects.filter(username=username).exists():
            error = 'Username already exists.'
        else:
            User.objects.create_user(username=username, email=email, password=password)
            return redirect('login')

    return render(request, 'register.html', {'error': error})


def login_page(request):
    return render(request, 'login.html')

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip17/account/urls.py
--------------------------------------------------------------------------------
from django.urls import path
from . import views

urlpatterns = [
    path('', views.home, name='home'),
    path('register/', views.register, name='register'),
    path('login/', views.login_page, name='login'),
]

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip17/slip17/urls.py
--------------------------------------------------------------------------------
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('account.urls')),
]

--------------------------------------------------------------------------------
FILE : home.html
PATH : slip17/account/templates/home.html
--------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Home</title>
</head>
<body>
  <h1>Welcome</h1>
  <a href="{% url 'register' %}">Register</a> |
  <a href="{% url 'login' %}">Login</a>
</body>
</html>

--------------------------------------------------------------------------------
FILE : login.html
PATH : slip17/account/templates/login.html
--------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Login</title>
</head>
<body>
  <h1>Login</h1>

  {% if error %}<p style="color:red">{{ error }}</p>{% endif %}

  <form method="post">
    {% csrf_token %}
    <p>Username: <input type="text" name="username" required></p>
    <p>Password: <input type="password" name="password" required></p>
    <button type="submit">Login</button>
  </form>

  <p>New user? <a href="{% url 'register' %}">Register</a></p>
</body>
</html>

--------------------------------------------------------------------------------
FILE : register.html
PATH : slip17/account/templates/register.html
--------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Register</title>
</head>
<body>
  <h1>Register</h1>

  {% if error %}<p style="color:red">{{ error }}</p>{% endif %}

  <form method="post">
    {% csrf_token %}
    <p>Username: <input type="text" name="username" required></p>
    <p>Email: <input type="email" name="email" required></p>
    <p>Password: <input type="password" name="password" required></p>
    <p>Confirm Password: <input type="password" name="cpassword" required></p>
    <button type="submit">Register</button>
  </form>

  <p>Already registered? <a href="{% url 'login' %}">Login</a></p>
</body>
</html>

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip17/account/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : apps.py
PATH : slip17/account/apps.py
--------------------------------------------------------------------------------
from django.apps import AppConfig


class AccountConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'account'

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip17/account/migrations/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : tests.py
PATH : slip17/account/tests.py
--------------------------------------------------------------------------------
from django.test import TestCase

# Create your tests here.

--------------------------------------------------------------------------------
FILE : manage.py
PATH : slip17/manage.py
--------------------------------------------------------------------------------
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip17.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip17/slip17/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : asgi.py
PATH : slip17/slip17/asgi.py
--------------------------------------------------------------------------------
"""
ASGI config for slip17 project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip17.settings')

application = get_asgi_application()

--------------------------------------------------------------------------------
FILE : wsgi.py
PATH : slip17/slip17/wsgi.py
--------------------------------------------------------------------------------
"""
WSGI config for slip17 project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip17.settings')

application = get_wsgi_application()

################################################################################
# SLIP 18 : User login and dashboard
################################################################################

QUESTION

Time: 3 hours | Marks: 25

1. Create a new Django project. Change the default view of the project and display login and register hyperlinks. Create a "Login form" using simple HTML tags. [10]
2. Implement code to authenticate user details and on successful login display the dashboard page. [10]
3. Viva [5]

FOLDER STRUCTURE

slip18/
|-- account/
|   |-- migrations/
|   |   `-- __init__.py
|   |-- templates/
|   |   |-- dashboard.html
|   |   |-- home.html
|   |   |-- login.html
|   |   `-- register.html
|   |-- __init__.py
|   |-- admin.py
|   |-- apps.py
|   |-- models.py
|   |-- tests.py
|   |-- urls.py
|   `-- views.py
|-- slip18/
|   |-- __init__.py
|   |-- asgi.py
|   |-- settings.py
|   |-- urls.py
|   `-- wsgi.py
`-- manage.py

--------------------------------------------------------------------------------
FILE : settings.py
PATH : slip18/slip18/settings.py
--------------------------------------------------------------------------------
"""
Django settings for slip18 project.

Generated by 'django-admin startproject' using Django 5.2.19.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-9v!doe^i(z^m6ppyd)jh=bufa2e5bote175+&%5=nzc@2yn9s+'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'account',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'slip18.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'slip18.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/5.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.2/howto/static-files/

STATIC_URL = 'static/'
LOGIN_URL = 'login'

# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

--------------------------------------------------------------------------------
FILE : models.py
PATH : slip18/account/models.py
--------------------------------------------------------------------------------
from django.db import models

# Create your models here.

--------------------------------------------------------------------------------
FILE : admin.py
PATH : slip18/account/admin.py
--------------------------------------------------------------------------------
from django.contrib import admin

# Register your models here.

--------------------------------------------------------------------------------
FILE : views.py
PATH : slip18/account/views.py
--------------------------------------------------------------------------------
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User


def home(request):
    return render(request, 'home.html')


def register(request):
    error = ''
    if request.method == 'POST':
        username = request.POST['username']
        email = request.POST['email']
        password = request.POST['password']
        cpassword = request.POST['cpassword']

        if password != cpassword:
            error = 'Passwords do not match.'
        elif User.objects.filter(username=username).exists():
            error = 'Username already exists.'
        else:
            User.objects.create_user(username=username, email=email, password=password)
            return redirect('login')

    return render(request, 'register.html', {'error': error})


def login_view(request):
    error = ''
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']

        user = authenticate(request, username=username, password=password)

        if user is not None:
            login(request, user)
            return redirect('dashboard')
        error = 'Invalid username or password.'

    return render(request, 'login.html', {'error': error})


@login_required
def dashboard(request):
    return render(request, 'dashboard.html')


def logout_view(request):
    if request.method == 'POST':
        logout(request)
    return redirect('login')

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip18/account/urls.py
--------------------------------------------------------------------------------
from django.urls import path
from . import views

urlpatterns = [
    path('', views.home, name='home'),
    path('register/', views.register, name='register'),
    path('login/', views.login_view, name='login'),
    path('dashboard/', views.dashboard, name='dashboard'),
    path('logout/', views.logout_view, name='logout'),
]

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip18/slip18/urls.py
--------------------------------------------------------------------------------
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('account.urls')),
]

--------------------------------------------------------------------------------
FILE : dashboard.html
PATH : slip18/account/templates/dashboard.html
--------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Dashboard</title>
</head>
<body>
  <h1>Dashboard</h1>
  <p>Welcome, {{ user.username }}!</p>

  <form method="post" action="{% url 'logout' %}">
    {% csrf_token %}
    <button type="submit">Logout</button>
  </form>
</body>
</html>

--------------------------------------------------------------------------------
FILE : home.html
PATH : slip18/account/templates/home.html
--------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Home</title>
</head>
<body>
  <h1>Welcome</h1>
  <a href="{% url 'register' %}">Register</a> |
  <a href="{% url 'login' %}">Login</a>
</body>
</html>

--------------------------------------------------------------------------------
FILE : login.html
PATH : slip18/account/templates/login.html
--------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Login</title>
</head>
<body>
  <h1>Login</h1>

  {% if error %}<p style="color:red">{{ error }}</p>{% endif %}

  <form method="post">
    {% csrf_token %}
    <p>Username: <input type="text" name="username" required></p>
    <p>Password: <input type="password" name="password" required></p>
    <button type="submit">Login</button>
  </form>

  <p>New user? <a href="{% url 'register' %}">Register</a></p>
</body>
</html>

--------------------------------------------------------------------------------
FILE : register.html
PATH : slip18/account/templates/register.html
--------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Register</title>
</head>
<body>
  <h1>Register</h1>

  {% if error %}<p style="color:red">{{ error }}</p>{% endif %}

  <form method="post">
    {% csrf_token %}
    <p>Username: <input type="text" name="username" required></p>
    <p>Email: <input type="email" name="email" required></p>
    <p>Password: <input type="password" name="password" required></p>
    <p>Confirm Password: <input type="password" name="cpassword" required></p>
    <button type="submit">Register</button>
  </form>

  <p>Already registered? <a href="{% url 'login' %}">Login</a></p>
</body>
</html>

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip18/account/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : apps.py
PATH : slip18/account/apps.py
--------------------------------------------------------------------------------
from django.apps import AppConfig


class AccountConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'account'

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip18/account/migrations/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : tests.py
PATH : slip18/account/tests.py
--------------------------------------------------------------------------------
from django.test import TestCase

# Create your tests here.

--------------------------------------------------------------------------------
FILE : manage.py
PATH : slip18/manage.py
--------------------------------------------------------------------------------
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip18.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip18/slip18/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : asgi.py
PATH : slip18/slip18/asgi.py
--------------------------------------------------------------------------------
"""
ASGI config for slip18 project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip18.settings')

application = get_asgi_application()

--------------------------------------------------------------------------------
FILE : wsgi.py
PATH : slip18/slip18/wsgi.py
--------------------------------------------------------------------------------
"""
WSGI config for slip18 project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip18.settings')

application = get_wsgi_application()

################################################################################
# SLIP 19 : User registration
################################################################################

QUESTION

Time: 3 hours | Marks: 25

1. Create a new Django project. Change the default view of the project and display login and register hyperlinks. Create a "Register form" using simple HTML tags. [10]
2. Implement code to register/insert user details into SQLite DB and on successful registration display the login page. [10]
3. Viva [5]

FOLDER STRUCTURE

slip19/
|-- account/
|   |-- migrations/
|   |   `-- __init__.py
|   |-- templates/
|   |   |-- home.html
|   |   |-- login.html
|   |   `-- register.html
|   |-- __init__.py
|   |-- admin.py
|   |-- apps.py
|   |-- models.py
|   |-- tests.py
|   |-- urls.py
|   `-- views.py
|-- slip19/
|   |-- __init__.py
|   |-- asgi.py
|   |-- settings.py
|   |-- urls.py
|   `-- wsgi.py
`-- manage.py

--------------------------------------------------------------------------------
FILE : settings.py
PATH : slip19/slip19/settings.py
--------------------------------------------------------------------------------
"""
Django settings for slip19 project.

Generated by 'django-admin startproject' using Django 5.2.19.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-(qmo^38rtq@j=^1s218li3!q6pts786j=4m6^ihn2bz9%hycjq'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'account',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'slip19.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'slip19.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/5.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.2/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

--------------------------------------------------------------------------------
FILE : models.py
PATH : slip19/account/models.py
--------------------------------------------------------------------------------
from django.db import models

# Create your models here.

--------------------------------------------------------------------------------
FILE : admin.py
PATH : slip19/account/admin.py
--------------------------------------------------------------------------------
from django.contrib import admin

# Register your models here.

--------------------------------------------------------------------------------
FILE : views.py
PATH : slip19/account/views.py
--------------------------------------------------------------------------------
from django.shortcuts import render, redirect
from django.contrib.auth.models import User


def home(request):
    return render(request, 'home.html')


def register(request):
    error = ''
    if request.method == 'POST':
        username = request.POST['username']
        email = request.POST['email']
        password = request.POST['password']
        cpassword = request.POST['cpassword']

        if password != cpassword:
            error = 'Passwords do not match.'
        elif User.objects.filter(username=username).exists():
            error = 'Username already exists.'
        else:
            User.objects.create_user(username=username, email=email, password=password)
            return redirect('login')

    return render(request, 'register.html', {'error': error})


def login_page(request):
    return render(request, 'login.html')

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip19/account/urls.py
--------------------------------------------------------------------------------
from django.urls import path
from . import views

urlpatterns = [
    path('', views.home, name='home'),
    path('register/', views.register, name='register'),
    path('login/', views.login_page, name='login'),
]

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip19/slip19/urls.py
--------------------------------------------------------------------------------
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('account.urls')),
]

--------------------------------------------------------------------------------
FILE : home.html
PATH : slip19/account/templates/home.html
--------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Home</title>
</head>
<body>
  <h1>Welcome</h1>
  <a href="{% url 'register' %}">Register</a> |
  <a href="{% url 'login' %}">Login</a>
</body>
</html>

--------------------------------------------------------------------------------
FILE : login.html
PATH : slip19/account/templates/login.html
--------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Login</title>
</head>
<body>
  <h1>Login</h1>

  {% if error %}<p style="color:red">{{ error }}</p>{% endif %}

  <form method="post">
    {% csrf_token %}
    <p>Username: <input type="text" name="username" required></p>
    <p>Password: <input type="password" name="password" required></p>
    <button type="submit">Login</button>
  </form>

  <p>New user? <a href="{% url 'register' %}">Register</a></p>
</body>
</html>

--------------------------------------------------------------------------------
FILE : register.html
PATH : slip19/account/templates/register.html
--------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Register</title>
</head>
<body>
  <h1>Register</h1>

  {% if error %}<p style="color:red">{{ error }}</p>{% endif %}

  <form method="post">
    {% csrf_token %}
    <p>Username: <input type="text" name="username" required></p>
    <p>Email: <input type="email" name="email" required></p>
    <p>Password: <input type="password" name="password" required></p>
    <p>Confirm Password: <input type="password" name="cpassword" required></p>
    <button type="submit">Register</button>
  </form>

  <p>Already registered? <a href="{% url 'login' %}">Login</a></p>
</body>
</html>

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip19/account/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : apps.py
PATH : slip19/account/apps.py
--------------------------------------------------------------------------------
from django.apps import AppConfig


class AccountConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'account'

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip19/account/migrations/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : tests.py
PATH : slip19/account/tests.py
--------------------------------------------------------------------------------
from django.test import TestCase

# Create your tests here.

--------------------------------------------------------------------------------
FILE : manage.py
PATH : slip19/manage.py
--------------------------------------------------------------------------------
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip19.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip19/slip19/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : asgi.py
PATH : slip19/slip19/asgi.py
--------------------------------------------------------------------------------
"""
ASGI config for slip19 project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip19.settings')

application = get_asgi_application()

--------------------------------------------------------------------------------
FILE : wsgi.py
PATH : slip19/slip19/wsgi.py
--------------------------------------------------------------------------------
"""
WSGI config for slip19 project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip19.settings')

application = get_wsgi_application()

################################################################################
# SLIP 20 : User login and dashboard
################################################################################

QUESTION

Time: 3 hours | Marks: 25

1. Create a new Django project. Change the default view of the project and display login and register hyperlinks. Create a "Login form" using simple HTML tags. [10]
2. Implement code to authenticate user details and on successful login display the dashboard page. [10]
3. Viva [5]

FOLDER STRUCTURE

slip20/
|-- account/
|   |-- migrations/
|   |   `-- __init__.py
|   |-- templates/
|   |   |-- dashboard.html
|   |   |-- home.html
|   |   |-- login.html
|   |   `-- register.html
|   |-- __init__.py
|   |-- admin.py
|   |-- apps.py
|   |-- models.py
|   |-- tests.py
|   |-- urls.py
|   `-- views.py
|-- slip20/
|   |-- __init__.py
|   |-- asgi.py
|   |-- settings.py
|   |-- urls.py
|   `-- wsgi.py
`-- manage.py

--------------------------------------------------------------------------------
FILE : settings.py
PATH : slip20/slip20/settings.py
--------------------------------------------------------------------------------
"""
Django settings for slip20 project.

Generated by 'django-admin startproject' using Django 5.2.19.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-!j(t$l)kpn4)e5*)spmvl0to+q)ybf-#w+)n&%ob+g%y)$g++k'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'account',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'slip20.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'slip20.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/5.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.2/howto/static-files/

STATIC_URL = 'static/'
LOGIN_URL = 'login'

# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

--------------------------------------------------------------------------------
FILE : models.py
PATH : slip20/account/models.py
--------------------------------------------------------------------------------
from django.db import models

# Create your models here.

--------------------------------------------------------------------------------
FILE : admin.py
PATH : slip20/account/admin.py
--------------------------------------------------------------------------------
from django.contrib import admin

# Register your models here.

--------------------------------------------------------------------------------
FILE : views.py
PATH : slip20/account/views.py
--------------------------------------------------------------------------------
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User


def home(request):
    return render(request, 'home.html')


def register(request):
    error = ''
    if request.method == 'POST':
        username = request.POST['username']
        email = request.POST['email']
        password = request.POST['password']
        cpassword = request.POST['cpassword']

        if password != cpassword:
            error = 'Passwords do not match.'
        elif User.objects.filter(username=username).exists():
            error = 'Username already exists.'
        else:
            User.objects.create_user(username=username, email=email, password=password)
            return redirect('login')

    return render(request, 'register.html', {'error': error})


def login_view(request):
    error = ''
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']

        user = authenticate(request, username=username, password=password)

        if user is not None:
            login(request, user)
            return redirect('dashboard')
        error = 'Invalid username or password.'

    return render(request, 'login.html', {'error': error})


@login_required
def dashboard(request):
    return render(request, 'dashboard.html')


def logout_view(request):
    if request.method == 'POST':
        logout(request)
    return redirect('login')

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip20/account/urls.py
--------------------------------------------------------------------------------
from django.urls import path
from . import views

urlpatterns = [
    path('', views.home, name='home'),
    path('register/', views.register, name='register'),
    path('login/', views.login_view, name='login'),
    path('dashboard/', views.dashboard, name='dashboard'),
    path('logout/', views.logout_view, name='logout'),
]

--------------------------------------------------------------------------------
FILE : urls.py
PATH : slip20/slip20/urls.py
--------------------------------------------------------------------------------
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('account.urls')),
]

--------------------------------------------------------------------------------
FILE : dashboard.html
PATH : slip20/account/templates/dashboard.html
--------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Dashboard</title>
</head>
<body>
  <h1>Dashboard</h1>
  <p>Welcome, {{ user.username }}!</p>

  <form method="post" action="{% url 'logout' %}">
    {% csrf_token %}
    <button type="submit">Logout</button>
  </form>
</body>
</html>

--------------------------------------------------------------------------------
FILE : home.html
PATH : slip20/account/templates/home.html
--------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Home</title>
</head>
<body>
  <h1>Welcome</h1>
  <a href="{% url 'register' %}">Register</a> |
  <a href="{% url 'login' %}">Login</a>
</body>
</html>

--------------------------------------------------------------------------------
FILE : login.html
PATH : slip20/account/templates/login.html
--------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Login</title>
</head>
<body>
  <h1>Login</h1>

  {% if error %}<p style="color:red">{{ error }}</p>{% endif %}

  <form method="post">
    {% csrf_token %}
    <p>Username: <input type="text" name="username" required></p>
    <p>Password: <input type="password" name="password" required></p>
    <button type="submit">Login</button>
  </form>

  <p>New user? <a href="{% url 'register' %}">Register</a></p>
</body>
</html>

--------------------------------------------------------------------------------
FILE : register.html
PATH : slip20/account/templates/register.html
--------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Register</title>
</head>
<body>
  <h1>Register</h1>

  {% if error %}<p style="color:red">{{ error }}</p>{% endif %}

  <form method="post">
    {% csrf_token %}
    <p>Username: <input type="text" name="username" required></p>
    <p>Email: <input type="email" name="email" required></p>
    <p>Password: <input type="password" name="password" required></p>
    <p>Confirm Password: <input type="password" name="cpassword" required></p>
    <button type="submit">Register</button>
  </form>

  <p>Already registered? <a href="{% url 'login' %}">Login</a></p>
</body>
</html>

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip20/account/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : apps.py
PATH : slip20/account/apps.py
--------------------------------------------------------------------------------
from django.apps import AppConfig


class AccountConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'account'

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip20/account/migrations/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : tests.py
PATH : slip20/account/tests.py
--------------------------------------------------------------------------------
from django.test import TestCase

# Create your tests here.

--------------------------------------------------------------------------------
FILE : manage.py
PATH : slip20/manage.py
--------------------------------------------------------------------------------
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip20.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

--------------------------------------------------------------------------------
FILE : __init__.py
PATH : slip20/slip20/__init__.py
--------------------------------------------------------------------------------
(empty file)

--------------------------------------------------------------------------------
FILE : asgi.py
PATH : slip20/slip20/asgi.py
--------------------------------------------------------------------------------
"""
ASGI config for slip20 project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip20.settings')

application = get_asgi_application()

--------------------------------------------------------------------------------
FILE : wsgi.py
PATH : slip20/slip20/wsgi.py
--------------------------------------------------------------------------------
"""
WSGI config for slip20 project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'slip20.settings')

application = get_wsgi_application()
