Implemented a ROT13 Encryption Web App

The Source Code for the Python Web App using Templates (jinja2):
[sourcecode language="python"]
import os #http://effbot.org/librarybook/os.htm operating system fumctions
import re #http://effbot.org/librarybook/re.htm regular expression module
from string import letters

import webapp2
import jinja2

from google.appengine.ext import db

template_dir = os.path.join(os.path.dirname(__file__), 'templates')
jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir), autoescape = True)

def render_str(template, **params):
t = jinja_env.get_template(template)
return t.render(params)

class MainHandler(webapp2.RequestHandler):
def render(self, template, **kw):
self.response.out.write(render_str(template, **kw))

def write(self, *a, **kw):
self.response.out.write(*a, **kw)

class Rot13(MainHandler):
def get(self):
self.render('rot13-form.html')

def post(self):
rot13 = ''
text = self.request.get('text')
if text:
rot13 = text.encode('rot13')

self.render('rot13-form.html', text=rot13)

app = webapp2.WSGIApplication([
('/', Rot13)],
debug=True)
[/sourcecode]
Source code for the Template positioned in a folder 'templates':
[sourcecode language="html"]</pre>
<!DOCTYPE html>

<html>
<head>
<title>Unit 2 Rot 13</title>
</head>

<body>
<h2>Enter some text to ROT13:</h2>
<form method="post">
<textarea name="text"
style="height: 100px; width: 400px;">{{text}}</textarea>
<br>
<input type="submit">
</form>
</body>

</html>[/sourcecode]

4 thoughts on “Implemented a ROT13 Encryption Web App”

    1. Hey Farbian, the content of the app.yaml is pretty standard. You can find the content below. If you you run into problems I’m happy to help you further! Best Regards, Dennis

      application: yourapplicationname
      version: 1
      runtime: python27
      api_version: 1
      threadsafe: yes

      handlers:
      – url: /static
      static_dir: static

      – url: .*
      script: main.app

      libraries:
      – name: jinja2
      version: latest

Leave a Reply