Examples

Examples source code of Applications built with Oreoweb

Simple Blogger Clone using Oreoweb

App.py

from Oreoweb import App, Templates
from models import db, Post

app = Oreoweb()


@app.route("/")
 def index(req, resp):
    posts = Post.select()
    resp.html = templates.render("index.html", {"posts": posts})


@app.route("/posts/{slug}")
def post(req, resp, slug):
    post = Post.select().where(Post.slug == slug).get()
    resp.html = templates.render("post.html", {"post": post})



if __name__ == '__main__':
    db.connect()
    db.create_tables([Post])
    app.run()
models.py

from peewee import CharField, DateTimeField, Model, SqliteDatabase, TextField

db = SqliteDatabase("my_database.db")


class Post(Model):
    title = CharField(max_length=255)
    slug = CharField(max_length=255, unique=True)
    summary = TextField()
    body = TextField()
    author_name = CharField(max_length=255)
    created_at = DateTimeField()

    class Meta:
        database = db

index.html

<!DOCTYPE html>

<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Posts</title>
</head>
<body>
  <h1>Posts</h1>
  {% if posts %}
    <ul>
        {% for post in posts %}
          <li>
            <h3><a href="/posts/{{post.slug}}">{{ post.title }} by {{ post.author_name }}</a></h3>
            <h4>{{post.summary}}</h4>
            <hr>
          </li>
        {% endfor %}
    </ul>
  {% else %}
    <p>No posts yet!</p>
  {% endif %}
</body>
</html>
Post.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>{{post.title}}</title>
</head>
<body>

<h1>{{post.title}}</h1>
Author: {{ post.author_name }} <br>
Date: {{ post.created_at }}

<p>
  {{ post.body }}
</p>

</body>
</html>

Last updated