Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

A Django app to require user acceptance of terms of service.

Project Description

This Django app adds support for versioned terms of service.


  1. Install with pip:

    $ pip install django-legal
  2. Add legal to your INSTALLED_APPS setting.

  3. (Optional) Add a new setting: LEGAL_TOS_NAME = 'terms_of_service'

  4. Update with the following:

    url(r'^legal/', include('legal.urls')),
  5. Create a new Agreement and AgreementVersion (ideally via data migration):

    # -*- coding: utf-8 -*-
    import os
    from south.v2 import DataMigration
    # This should be the same value as LEGAL_TOS_NAME (if you overrode it)
    AGREEMENT_NAME = 'tos'
    class Migration(DataMigration):
        def forwards(self, orm):
            agreement, created = orm['legal.Agreement'].objects.get_or_create(name=AGREEMENT_NAME)
            # This file should live in the same directory as the migration
            f = open('%s/tos_content_2013_08_01.html' % os.path.dirname(__file__), 'r')
            orm['legal.AgreementVersion'].objects.create(agreement=agreement, date='2013-08-01',
        def backwards(self, orm):
            agreement = orm['legal.Agreement'].objects.get(name=AGREEMENT_NAME)
        models = {
            'legal.agreement': {
                'Meta': {'object_name': 'Agreement'},
                'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
                'name': (
                    'django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '50', 'db_index': 'True'})
            'legal.agreementversion': {
                'Meta': {'ordering': "['-date']", 'unique_together': "(('agreement', 'date'),)",
                         'object_name': 'AgreementVersion'},
                'agreement': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['legal.Agreement']"}),
                'content': ('django.db.models.fields.TextField', [], {}),
                'date': ('django.db.models.fields.DateTimeField', [], {}),
                'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
        # Change this to be the name of the app where the migration lives
        complete_apps = ['my-app']
        symmetrical = True

Testing This App

A modified and Django settings file are included to test this app:

$ python test

Testing Your App

You may find the middleware a bit excessive for your tests as it requires you to create an agreement and version, and accept the agreement on behalf of your tests users. If you want to disable the middleware, add the following to your settings:

if 'test' in sys.argv:
Release History

Release History

This version
History Node


History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django-legal-1.0.tar.gz (8.4 kB) Copy SHA256 Checksum SHA256 Source Mar 21, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting