Django Tutorial - Video 11 - Interactive Facebook Tabs part 2

This tutorial covers building the View and Template to serve the page for the Facebook Tab directly into a Facebook Fan Page.


facebooktab/views.py

from django.shortcuts import render_to_response
from django.template import RequestContext
from django.views.decorators.csrf import csrf_exempt
from beer.models import Beer

@csrf_exempt
def BeerGifter(request):
        beers = Beer.objects.all().order_by('name')
        context = {'beers': beers}
        return render_to_response('facebooktab/beergifter.html', context, context_instance=RequestContext(request))
		

templates/facebooktab/beergifter.html

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js" type="text/javascript"></script>
<style>
#fb_header{background: url(/media/images/facebook_header.jpg) no-repeat scroll top center #000000;width:790px;height:200px;}
#fb_beers{background: url(/media/images/beer_wall_bg.jpg) repeat-y top center #000000;width:790px;}
.beer_ul{background: url(/media/images/beer_wall_shelf.png) no-repeat scroll 0 158px transparent;margin:0;padding:0 70px;width:650px;height:300px;list-style:none outside none;}
.beer_ul li{float:left;text-align:center;width:108px;}
.beer_ul li p{color:#DC0000;margin-top:30px;}
</style>
</head>
<body>
<div id="fb_container">
        <div id="fb_header">
                <img src="/media/images/header_logo.png" />
        </div>
        <div id="fb_beers">
                <ul class="beer_ul">
                {% for beer in beers %}
                        <li>
                        <a href="/beers/{{ beer.slug }}/"><img src="{{ beer.image1.url }}" /></a>
                        <p>{{ beer.name }}</p>
                        </li>
                {% if forloop.counter|divisibleby:"6" and not forloop.last %}</ul><ul class="beer_ul">{% endif %}
                {% endfor %}
                </ul>
        </div>
</div>
</body>
</html>