-
-
Save LuanP/f8e23553f2aa03e0d459 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render, get_object_or_404 | |
from .models import Course | |
from .forms import ContactCourse | |
def index(request): | |
courses = Course.objects.all() | |
template_name = 'courses/index.html' | |
context = { | |
'courses': courses | |
} | |
return render(request, template_name, context) | |
# def details(request, pk): | |
# course = get_object_or_404(Course, pk=pk) | |
# context = { | |
# 'course' : course | |
# } | |
# template_name = 'courses/details.html' | |
# return render(request, template_name, context) | |
def details(request, slug): | |
course = get_object_or_404(Course, slug=slug) | |
if request.method == 'POST': | |
form = ContactCourse(request.POST) | |
else: | |
form = ContactCourse() | |
context = { | |
'course': course, | |
'form': form | |
} | |
template_name = 'courses/details.html' | |
return render(request, template_name, context) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment