Commit 6b789112 authored by kylemendozaa's avatar kylemendozaa

converted the index funtion to a cbv

parent b18c3340
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
<img src="{% static 'assignment1.jpg' %}"> <img src="{% static 'assignment1.jpg' %}">
{% elif assignment.id == 2 %} {% elif assignment.id == 2 %}
<img src="{% static 'assignment2.jpg' %}"> <img src="{% static 'assignment2.jpg' %}">
{% elif assigment.id == 3 %} {% elif assignment.id == 3 %}
<img src="{% static 'code.jpg' %}"> <img src="{% static 'code.jpg' %}">
{% endif %} {% endif %}
......
from django.urls import path from django.urls import path
from .views import index, AssignmentDetailView, new_assignment from .views import IndexView, AssignmentDetailView, new_assignment
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', IndexView.as_view(), name='index'),
path('<int:pk>/details/', AssignmentDetailView.as_view(), name='assignment-details'), path('<int:pk>/details/', AssignmentDetailView.as_view(), name='assignment-details'),
path('add/', new_assignment, name='new-assignment') path('add/', new_assignment, name='new-assignment')
] ]
......
...@@ -2,13 +2,15 @@ from django.shortcuts import render, redirect ...@@ -2,13 +2,15 @@ from django.shortcuts import render, redirect
from django.http import HttpResponse from django.http import HttpResponse
from django.template import loader from django.template import loader
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.base import TemplateView
from .models import Assignment, Course from .models import Assignment, Course
from .forms import AssignmentForm from .forms import AssignmentForm
# Create your views here. # Create your views here.
def index(request): class IndexView(TemplateView):
def get(self, request):
context = { context = {
"courses": Course.objects.order_by("course_code"), "courses": Course.objects.order_by("course_code"),
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment