Building a White Labeled eSignature Flow using Django and the HelloSign API

"Building a White Labeled eSignature Flow using Django and the HelloSign API" header image

When your application requires users to sign contracts and agreements, you likely want to keep the experience on your site. You can maintain control of what users see and still have the benefits of a secure eSignature platform.


Just as Django allows you to build more with less code, HelloSign’s embedded eSignatures give you the tools to create a great experience, this allows your users to address their business needs in a unique and customized approach — whether it’s to improve an HR onboarding experience for new employees or to streamline contracting for a sales team. In this guide, we will be using a sample project which allows teachers in a school to have different forms signed by parents, we’ll walk you through how to create a custom white-labeled eSignature flow for Django, from installing the HelloSign SDK in pip to finishing with a script import into your Django templates.


To get started, you can visit our Developer Portal and start testing for free (no credit card required).


Add HelloSign to your app’s Virtual Environment and Customize with White Labeling

You will want to create your Django project with two apps: an admin app and a user portal app.  

Inside your project’s virtual environment, install HelloSign’s Python SDK.  Be sure that it is available to both the admin and user apps.


You will need to create a HelloSign account to generate an API key.  You can find your API key under the API tab on the Settings page of your account.  You will also need to create a HelloSign API App. In the same page where you get the key, click on “Create” in the API Apps section.  Give your API App a name and a domain. While you are in the testing phases of development, you can ignore the domain verification fields on the HelloSign dashboard or enter any URL you like, as those are only required for production uses.


Once you have created an application, you will receive a Client ID associated with that specific API App.  As a best practice, secure both your API key and Client ID in a .env file.  


By using the White Labeling feature, you can customize the look of your HelloSign eSignature experience to match your organization’s color scheme.  Using the Update API App endpoint and initiating the API call from the admin side of your Django project, specify the elements you would like to customize:


littleschool/admin/views.py

  
    client = HSClient(api_key='YOUR_HS_API_KEY')
    client.update_api_app(
          client_id="YOUR CLIENT ID",
          white_labeling_options ={
                “primary_button_color”: “#987282”,
                “primary_button_text_color”: “fdfdf6”}
            )
  

You can find more information in the White Labeling documentation


Create a Forms Page for Users

HelloSign offers developers the ability to embed the signing experience directly in their websites, making the process of collecting documents with legally-binding eSignature from your clients or users feel like a seamless part of their experience on your website.


The Little School, has a website built in Django to accommodate Parent, Child, and Teacher profiles, making use of Django’s built-in auth features.  Each Parent object is associated with a specific authenticated User:


littleschool/models.py

  
    class Parent(models.Model):
        user = models.OneToOneField(User, on_delete=models.CASCADE)
        children = models.ForeignKey(Child, related_name="parent", on_delete=models.CASCADE)
  

When parents log in to the school’s website, they are directed to a list of forms in the parent_portal app within the Django project file. Here, the school can post enrollment forms, field trip permission slips, and health forms.  All the files available through these links can be handled with the HelloSign client, creating a centralized location for all the school’s required waivers and contracts.


If a project is set up with a relational database, including the default sqlite3, an admin user could control which forms appear on a given user profile by using the Teacher-Child relationship in models.py to send certain forms to a Parent user’s views.


Create HelloSign Client and Methods

The embedding signing flow means users can view, sign, and review their contracts and waivers while still on your website.  Using HelloSign’s Embedded Signing functionality allows you to display your SignatureRequests as <iframe> HTML elements and does not require any additional user accounts or authentication beyond what you already have on your site.  


Inside the parent_portal file directory, create a file called hellosignclient.py.  In this file, you will add the code to create embedded eSignature requests and display documents for signature at a unique URL.  You can create a single SignatureRequest method and reuse it for multiple forms:


littleschool/parent_portal/hellosignclient.py

  
    from decouple import config
    from hellosign_sdk import HSClient
    from django.contrib.auth.Models import User
     
    client = HSClient(config('YOUR_HS_API_KEY'))
     
    def sign_request(subject, message, User, files):
       user_info = dict()
       user_info["name"] = User.get_full_name(),
       user_info["email_address"] = User.email,
       signers = [],
       signers.append(user_info),
      
       client.send_signature_request_embedded(
           test_mode = True,
           client_id = config('YOUR_HS_CLIENT_ID'),
           subject = subject,
           message = message,
           signers = signers,
           files = files
       )
     
     
    def enrollment():
       sign_request(
           subject = "Enrollment Form 2021-2022",
           message = "Please sign to enroll your child for the 2021-2022 school year.",
           files.append("enrollment_form.pdf", "tuition_addendum.pdf")
           )
       for signature in sign_request.signatures:
           embedded_obj = client.get_embedded_object(signature.signature_id)
           sign_url = embedded_obj.sign_url
     
       return sign_request, sign_url
  

Here, we are using the pip package python-decouple to handle variables from our .env file.  


Then, we import the HelloSign Client and Django User.  The sign_request method is a reusable method that associates the logged-in User with the request to HelloSign.  

In the enrollment method, the reusable sign_request method is called and given parameters specific to the enrollment form.  Then, HelloSign generates a unique ID for the signer which is passed as part of the get_embedded_object request.  The function returns the unique URL for the User’s signature.  


Display the Embedded Signature Request

If you have built your front end using Django Templates or Jinja2, you can still use HelloSign’s JavaScript client-facing Embedded Signature Request UI.


First, use npm to install the HelloSign Embedded package.  If you are not using npm, it is still possible to install it via CDN, manual download, or by compiling from the source by visiting HelloSign’s wiki.  


Then, create a file called hellosign.js to call the front-end client:


littleschool/parent_portal/hellosign.js

  
    import HelloSign from 'hellosign-embedded';
    
    const client = new HelloSign();
    
    const clientSign = () => {
      client.open(signUrl, {
      clientId: `${process.env.YOUR_HS_CLIENT_ID}`
      });
    }
    
    clientSign.open(signUrl, {
      testMode: true
    });
    
    clientSign.on('sign', () => {
      alert('The document has been signed!');
    });
  

This script, which gets the signURL variable passed from views.py, can be embedded in your HTML templates, either in the <head> or <body>.  In this case, in order to make the <script> element callable from multiple templates, we’ve opted to put it in the <head> inside base.html:


littleschool/parent_portal/templates/base.html

  
    //...
    <head>
      <script src="../hellosign.js"></script>
    </head>
    //...
  

Then, from inside the `enrollment.html` template, we call the method with an onClick function:


littleschool/parent_portal/templates/enrollment.html

  
    //...
      <input type="button" onclick="signEnrollment()" value="Sign Enrollment Forms">
    //...
  

Get Confirmation When Documents Are Signed

It’s best to monitor completion of eSignature requests in a separate admin app.  In the case of a school, this might be the app used by just the Enrollment Director, or it could be accessible to all staff.  Either way, keep this functionality separate from the parent_portal.  


Use the signature_request_id of the desired SignatureRequest to call the HelloSign API for the current status using the Get Signature Request endpoint. If desired, those results can be sorted or filtered - for example, an administrator might want to see all kindergarten enrollment forms, or a teacher might want field trip forms for just the students in one class.  


Your admin app can follow a similar setup to the parent_portal, or you can locate the HelloSign files - hellosign.js and hellosignclient.py in a directory where both Django apps have access, perhaps determined by the scale of your admin functionality.  Either way, the calls to the HelloSign client will use the same API credential as the parent_portal methods.  


The get_signature_request endpoints, both individual and list,  will return a signature_request object, which will contain the status of each signature:


littleschool/admin/hellosignclient.py

  
  //...
    client = HSClient(api_key='YOUR_HS_API_KEY')
    //To get an individual SignatureRequest:
    request = client.get_signature_request('SIGNATURE_ID')
    //To get all SignatureRequests associated with your account:
    all_requests = client.get_signature_request_list()
    //To get status for each signature within the signature_request object as a dictionary of name & status:
    for r in all_requests:
        signer_status = {}
        for s in r.signatures:
              signer = s.signer_name
              status = s.status
              signer_status[signer]: status
        return signer_status    
  //...
  

At any point during the SignatureRequest process, you can download your files to see the current version.  To do this, you’ll need to have a file management system installed in your application, like the basic PyPi file system, fs.  You can download .zip or PDF files:


littleschool/admin/views.py

  
    //...
      const fs = require('fs');
      const hellosign = require('hellosign-sdk')({ key: 'YOUR_HS_API_KEY' });
      hellosign.signatureRequest.download(signatureRequestId, { file_type: 'zip' }, (err, res) => {
        const file = fs.createWriteStream('files.zip');
        res.pipe(file);
        file.on('finish', () => {
          file.close();
        });
      });
    //...
  

So long as you maintain your HelloSign account, you’ll have ongoing access to your files through the API, or you can set up your system to download them and save them locally or to a cloud drive.


HelloSign offers a great deal more functionality, and as your application scales, that functionality and Django’s flexibility will work together to deliver a seamless experience! To learn more about the HelloSign API and start testing for free, visit HelloSign’s Developer Portal

Ready to integrate signatures into your app or website?

Let us help you build a custom API plan that fits your unique business needs.

Get news, insights and posts directly in your inbox

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form
Oops! Something went wrong while submitting the form.