Skip to main content

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:

Project details

Download files

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

Source Distribution

django-legal-1.0.tar.gz (8.4 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page