Skip to content

Instantly share code, notes, and snippets.

@mcburton
Forked from anonymous/bottling.py
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcburton/9103617 to your computer and use it in GitHub Desktop.
Save mcburton/9103617 to your computer and use it in GitHub Desktop.
added rough API sketch and some fooling with templates
from bottle import route, run, template, static_file, error, SimpleTemplate
## this is a test
@route('/')
def home():
return base_template.render(title="hi", content="what?")
@route('/static/<filename>')
def static(filename):
return static_file(filename, root='')
@error(404)
def err(error):
return "barf"
#### templates
base_template = SimpleTemplate("""
<html>
<head>
<title>{{title}}</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
</head>
<body>
{{ content }}
</body>
</html>
""")
#### API for my datar
@route('/blogs')
@route('/blogs/')
def blogs():
return "a list of all the blogs in the database with some metadata"
@route('/blogs/<blogID:path>')
@route('/blogs/<blogID:path>/')
def blog(blogID):
return "A dashboard page with summary and metadata about a particular blog identified by blogID"
@route('/blogs/<blogID:path>/posts')
@route('/blogs/<blogID:path>/posts/')
def posts(blogID):
return "A listing of all the posts(paginated?) for blogID"
@route('/blogs/<blogID:path>/posts/<postID:path>')
@route('/blogs/<blogID:path>/posts/<postID:path>/')
def post(blogID, postID):
return "a page with all the data and metadata associated with postID"
# run the server
run(host="localhost", port=8080, debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment