Front End


RapidSMS provides an optional framework for making the applications on your site have a common look and feel.

Starting with release 0.12.0, the framework uses Twitter Bootstrap, v2.2.2.

This document is intended to describe how the contrib apps use Bootstrap, and how you might use it in your own apps.

Base template

Your templates should extend base.html, either directly or indirectly. That will load Bootstrap and set up the common page structure for RapidSMS apps.

The simplest way to provide content for your page is to override {% block content %}. That block is rendered inside of a Bootstrap fluid row like this:

<div class="row-fluid content">
   {% block content %}{% endblock %}

You can then divide your page into columns using Bootstrap span classes:

{% block content %}
  <div class="span6">  Left side   </div>
  <div class="span6">  Right side  </div>
{% endblock %}

See the Bootstrap documentation for more things you can do inside a fluid row to affect the layout.


Set the page title with {% block title %}:

{% block title %}Send a Text Message{% endblock title %}

Additional styles

If you have a page that needs additional stylesheets, you can override {% block extra_stylesheets %}:

{% block extra_stylesheets %}
  <link type="text/css" rel="stylesheet"
        href="{{ STATIC_URL }}my-app/stylesheets/my-app.css" />
{% endblock %}

Additional javascript

Additional javascript can be added by overriding {% extra_javascript %}:

{% block extra_javascript %}
  <script src="{{ STATIC_URL }}my-app/js/my-app.js"
{% endblock %}

Top menu

The menu at the top of the page is a Bootstrap navigation bar.

Your site can configure the links that appear between the RapidSMS logo and the login/logout link by overriding the rapidsms/_nav_bar.html template. You can do this by creating a file with this path from the top of your project: templates/rapidsms/_nav_bar.html.

Your template will be included in the base page template. It should contain <li> elements for each link. Example:

{% load url from future %}
<li><a href="{% url 'app1' %}">App1</a></li>
<li><a href="{% url 'app2' %}">App2</a></li>
<li><a href="{% url 'app3' %}">App3</a></li>


Keep these links short. If the links take up too much room on the page, they will wrap in the header, forcing the bottom of the page header down and overlapping part of the page.


To include tables in a page, the django_tables2 package works well. Look at the rapidsms.contrib.messagelog app for an example. Note particularly how the view overrides the default template used by django_tables2 to use one that takes advantage of Bootstrap styling.


Bootstrap can make forms look nice too. RapidSMS’s form tags have been updated to work well with Bootstrap. The render_form tag will render your form’s data fields correctly for Bootstrap. Then all you have to do is add any submit buttons you need, properly marked up. See the Bootstrap documentation for full details, but here’s an example from another contrib app, rapidsms.contrib.httptester:

 {% extends "base.html" %}
 {% load forms_tags %}
 {% block content %}
   <div class="page-header">
     <h1>Message Tester</h1>

     <div class="span4">
         <form action="" method="post" enctype="multipart/form-data">
           {% render_form message_form %}
           {% csrf_token %}

           <div class="form-actions">
             <button type="submit" class="btn btn-primary" id="send-btn" name="send-btn">Send</button>
             <label for="send-btn">Send single or multiple messages</label>
     <div class="span8">

 {% endblock %}

Messages to Users

If you use the Django messages framework to send messages to your users, the base template will display them nicely above the page content.