-
-
Save mcburton/9103617 to your computer and use it in GitHub Desktop.
added rough API sketch and some fooling with templates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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