Laws.Africa Developer Guide
  • Laws.Africa Developer Guide
  • Get Started
    • Introduction
    • Quick start
    • Works and expressions
    • Webhooks
    • Changelog
  • Tutorial
    • About the tutorial
    • Module 1: Build a legislation reader
      • Introductory concepts
      • Create a basic Django app
      • Create database models
      • Fetching the data
      • Work listing page
      • Expression detail page
      • Styling with Law Widgets
      • Adding interactivity
      • Staying up to date
    • Module 2: Enrichments and interactivity
      • Basic enrichments
      • Advanced enrichments
      • Advanced interactivity
    • Module 3: Text extraction for search and analysis
      • Why extracting text is important
      • Basics of text extraction
      • Advanced text extraction
      • Extracting text for analysis and machine learning
  • Content API Reference
    • About the Content API
    • Authentication
    • Pagination
    • Places
    • All work expressions
    • Single work expression
      • Commencements
      • Embedded images
      • Publication document
      • Table of Contents
      • Timeline
    • Taxonomy topics
    • Enrichment datasets
  • AI API Reference
    • About the AI API
    • Authentication
    • Knowledge Bases
  • How-to Guides
    • How to use the Table of Contents API
    • How to download images
Powered by GitBook
On this page
  • In this section
  • Expression detail page
  1. Tutorial
  2. Module 1: Build a legislation reader

Expression detail page

Add a document detail page.

In this section

  • Displaying the details and content of an expression

Expression detail page

Now let's add an expression detail page that shows the content of a single expression of a work.

Add a new view to your views.py:

views.py
from django.views.generic import ListView, DetailView
from .models import Work, Expression

class WorkListView(ListView):
    model = Work
    
class ExpressionDetailView(DetailView):
    model = Expression
    slug_field = 'frbr_uri'
    slug_url_kwarg = 'frbr_uri'

Add the new view to your urls.py:

urls.py
from django.urls import path
from reader.views import *

urlpatterns = [
    path('', WorkListView.as_view(), name="home"),
    # the FRBR URI starts with a /
    path('expression<path:frbr_uri>', ExpressionDetailView.as_view(), name="expression"),
]

Now create a template called templates/reader/expression_detail.html. We'll start with just the title and the expression content.

expression_detail.html
<html>
<head>
  <title>{{ expression.title }}</title>
</head>
<body>
  <a href="{% url 'home' %}">Home</a>
  
  <h1>{{ expression.title }}</h1>
  
  <div>{{ expression.content|safe }}</div>
</body>

If there are other expressions on the same work (different language or date), how would the user find them?

If you visit an expression detail page, you'll see the title and some ugly content. In the next section we'll add formatting to the content.

PreviousWork listing pageNextStyling with Law Widgets

Last updated 1 year ago