Skip to content

Instantly share code, notes, and snippets.

@LuanP
Forked from anonymous/gist:022b68aff42c00ccf593
Created June 22, 2015 15:12
Show Gist options
  • Save LuanP/f8e23553f2aa03e0d459 to your computer and use it in GitHub Desktop.
Save LuanP/f8e23553f2aa03e0d459 to your computer and use it in GitHub Desktop.
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