Commit 6b789112 authored by kylemendozaa's avatar kylemendozaa

converted the index funtion to a cbv

parent b18c3340
......@@ -16,7 +16,7 @@
<img src="{% static 'assignment1.jpg' %}">
{% elif assignment.id == 2 %}
<img src="{% static 'assignment2.jpg' %}">
{% elif assigment.id == 3 %}
{% elif assignment.id == 3 %}
<img src="{% static 'code.jpg' %}">
{% endif %}
......
from django.urls import path
from .views import index, AssignmentDetailView, new_assignment
from .views import IndexView, AssignmentDetailView, new_assignment
urlpatterns = [
path('', index, name='index'),
path('', IndexView.as_view(), name='index'),
path('<int:pk>/details/', AssignmentDetailView.as_view(), name='assignment-details'),
path('add/', new_assignment, name='new-assignment')
]
......
......@@ -2,18 +2,20 @@ from django.shortcuts import render, redirect
from django.http import HttpResponse
from django.template import loader
from django.views.generic.detail import DetailView
from django.views.generic.base import TemplateView
from .models import Assignment, Course
from .forms import AssignmentForm
# Create your views here.
def index(request):
context = {
"courses": Course.objects.order_by("course_code"),
}
template = loader.get_template("assignments/index.html")
return HttpResponse(template.render(context, request))
class IndexView(TemplateView):
def get(self, request):
context = {
"courses": Course.objects.order_by("course_code"),
}
template = loader.get_template("assignments/index.html")
return HttpResponse(template.render(context, request))
class AssignmentDetailView(DetailView):
model = Assignment
......
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