Module 5

From CSE330 Wiki
Revision as of 07:49, 8 April 2013 by Shane (talk | contribs)
Jump to navigationJump to search

In Module 6, you will learn about python, a programming language, and Django, a web framework.

This article contains your assignments for Module 6.

Individual Assignments

Django Tutorial

Install Djgano

This procedure assumes you are using and Amazon AMI Linux on an ec2 instance. An in-depth install guide can be found on the Django website, but a quick version is below.

That's it.

Django Assignment

Complete the tutorial on the django website. You will create a Polls app. There are four parts to this tutorial.

It is important you do all the steps in the tutorial to get comfortable defining models, views, templates, and using the interactive shell and the admin app. Understanding the concepts will make the project go much quicker.

  • Part 1
    • Create a project
    • Start the development server
    • Setup an SQLite database
    • Create the Polls app and define the models
    • Interact with the database using the interactive python shell
  • Part 2
    • Activate the admin site
    • Add the poll app to the admin site
    • Modify the database using the admin site
  • Part 3
    • Configure URL handling
    • Create some views
  • Part 4
    • Write a form that modifies the database
    • Refactor to use generic views
    Switch to Apache Webserver
    • run sudo yum install mod_wsgi to install the apache and the module necessary for serving your django app.
    • Add these lines to /etc/httpd/conf/httpd.conf
      Alias /static /var/www/mysite/static
      <Directory /var/www/mysite/static>
        Order deny,allow
        Allow from all
      WSGIScriptAlias / /var/www/mysite/apache/django.wsgi
    • Move your "mysite" project (the top level mysite directory) to /var/www and make the directory /var/www/mysite/apache. In that directory create the file django.wsgi and inside that file put:
      import os
      import sys
      os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
      import django.core.handlers.wsgi
      application = django.core.handlers.wsgi.WSGIHandler()
  • Be sure to change any references to old paths in the django "mysite" file (such as the location of the database if using sqlite) and restart the webserver.
  • Also make sure the permissions are setup properly on the mysite directory under /var/www for apache to access, along with the database file (if using sqlite3).
  • To fix the issue with the CSS not loading on the admin page you need to create a directory under the static folder (/var/www/mysite/static/admin/css/) and copy the files from /usr/lib/python2.6/site-packages/django/contrib/admin/static/admin/css/ into it.

Group Project

You may work in pairs on this project. Your group will create an image tagging and browsing site using Django as described below.

Image Tagging/Browsing Site

A site that lets users upload images, apply multiple tags to them, and browse through images of a certain tag. When looking at an image, it lists all associated tags so you can switch albums.


  • Make a database that stores images and tags. An image can have multiple tags, and each tag can have multiple images.
  • The home page should allow users to find tags that they want to view. (e.g. lolcat).
  • After clicking a link to a tag, it should take you to a page with the newest image for that tag.
  • Clicking on the current image should take to to the next image according to date added. When at the last image, link to the first.
  • Make it clear which tag you are currently browsing. Beside or below the current image, also display the full list of tags that belong to the current image (e.g. lolcat, meme, internet, funny). You should be able to click on any of the tags to begin looking through that collection of images.
  • Provide a way for users who are logged in to add new images and new tags.
  • Validate user input
  • Provide a way for users to register, login, and change their password.
  • Have a link that sends an email to a user with a link for resetting their password in case they forget it.
  • Style the site with statically-served CSS (i.e. link to static .css files and don't write CSS inside the html templates)


  • You may store images as external web links.
  • Try to find and figure out as many Django shortcuts as you can. You do not need to write your own url parsing, validation, login/registration/reset forms etc. For these common tasks, there is almost always built-in functionality that will do what you want in very few lines.
  • The admin interface and the interactive python shell will be very helpful when getting started with the database.


Due Date: Wednesday December 5th by 1pm (both individual and group)

Python Assignment (Individual) Points
Compute Final Grades 0.25
Compute Letter Grade 0.25
Sort by Last Name 0.25
Accept Command Line Argument 0.25
Django Assignment (Individual)
Models defined, database set up 0.25
Admin app enabled and working 0.25
URLs matched to correct views 0.25
Templates for viewing and voting using generic views 0.25
Apache serving the site 0.5
Group Portion:
Models defined and database set up 1
View of single image with current tag and list of all tags 1
Navigation between images and tags 0.5
Main page displays all tags sorted by number of images 0.5
User registration, login/logout and change password 0.5
Forgot password sends email with working reset link 0.5
Validation of URLs submitted by user (or upload) 0.5
Add new images and tags, only if logged in 0.5
Static CSS applied to some templates 0.5
Creative Portion 2

Total Points = 10

Turn in after 1pm on the 5th = 1 point off

Turn in on the 6th = 2 points off

Turn in on the 7th = 3 points off

All projects should be completed by the last day of class, Friday the 7th. Any modules that have not been demo'd at that time will be given a grade of zero. You are responsible for making sure you can attend TA hours to demo if you are late (or for contacting a TA to try and arrange a session). You cannot demo by e-mail.