from django.http import HttpResponse
from django.shortcuts import render_to_response
from .models import Resource

def index(request):
    return render_to_response("index.html")

def allresources(request):
	mdict = {
		"resources": Resource.objects.all()
	}
	return render_to_response("resources_main.html", mdict)

def specificresource(request, resource_pk):
	mdict = {
		"resource": Resource.objects.get(pk=resource_pk)
	}
	return render_to_response("resource.html", mdict)

from django.http import Http404
from django.shortcuts import render_to_response
from .models import Resource

def index(request):
    return render_to_response("index.html")

def allresources(request):
	mdict = {
		"resources": Resource.objects.all()
	}
	return render_to_response("resources_main.html", mdict)

def specificresource(request, resource_pk):
	try:
		mdict = {
			"resource": Resource.objects.get(pk=resource_pk)
		}
	except Resource.DoesNotExist:
		raise Http404("No resources with that primary key were found.")
	return render_to_response("resource.html", mdict)

Add check to make sure resource exists
Add check to make sure resource exists

- from django.http import HttpResponse
+ from django.http import Http404
  from django.shortcuts import render_to_response
  from .models import Resource
  
  def index(request):
      return render_to_response("index.html")
  
  def allresources(request):
  	mdict = {
  		"resources": Resource.objects.all()
  	}
  	return render_to_response("resources_main.html", mdict)
  
  def specificresource(request, resource_pk):
+ 	try:
- 	mdict = {
+ 		mdict = {
- 		"resource": Resource.objects.get(pk=resource_pk)
+ 			"resource": Resource.objects.get(pk=resource_pk)
- 	}
+ 		}
+ 	except Resource.DoesNotExist:
+ 		raise Http404("No resources with that primary key were found.")
  	return render_to_response("resource.html", mdict)
  
Add check to make sure resource exists
## Code Before:
from django.http import HttpResponse
from django.shortcuts import render_to_response
from .models import Resource

def index(request):
    return render_to_response("index.html")

def allresources(request):
	mdict = {
		"resources": Resource.objects.all()
	}
	return render_to_response("resources_main.html", mdict)

def specificresource(request, resource_pk):
	mdict = {
		"resource": Resource.objects.get(pk=resource_pk)
	}
	return render_to_response("resource.html", mdict)

## Instruction:
Add check to make sure resource exists
## Code After:
from django.http import Http404
from django.shortcuts import render_to_response
from .models import Resource

def index(request):
    return render_to_response("index.html")

def allresources(request):
	mdict = {
		"resources": Resource.objects.all()
	}
	return render_to_response("resources_main.html", mdict)

def specificresource(request, resource_pk):
	try:
		mdict = {
			"resource": Resource.objects.get(pk=resource_pk)
		}
	except Resource.DoesNotExist:
		raise Http404("No resources with that primary key were found.")
	return render_to_response("resource.html", mdict)
