Add a Send SMS View
Add a view that renders a Jinja2 template for the web application. Create this template at templates/index.html:
@app.route('/')
def index():
""" A view that renders the Send SMS form. """
return render_template('index.html')
The following HTML includes the Bootstrap CSS framework and then renders a form with two fields: to_number for taking the destination phone number and message, so the user can enter their SMS message.
<h1>Send an SMS</h1>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<div class="container">
<h1>Send an SMS</h1>
<form action="/send_sms" method="POST">
<div class="form-group"><label for="destination">Phone Number</label>
<input id="to_number" class="form-control" name="to_number" type="tel" placeholder="Phone Number" /></div>
<div class="form-group"><label for="message">Message</label>
<textarea id="message" class="form-control" name="message" placeholder="Your message goes here"></textarea></div>
<button class="btn btn-default" type="submit">Send SMS</button>
</form>
</div>
How to Send SMS Messages with Python, Flask and Nexmo
This tutorial introduces you to sending SMS with Python, making use of the Nexmo Python library. It starts by showing how to send SMS from the REPL, then goes on to show you how to build a simple flask app with SMS capabilities.
Steps
1
Introduction to this tutorial2
Prerequisites3
Install the Vonage Python Server SDK4
Send an SMS from the Python REPL5
Set up an SMS Sending Flask App6
Add a Send SMS View7
Run the Flask Server8
Handle the Form Post9
What's next?