A flat-file CMS written in Python and Flask
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

app.py 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from flask import Flask, redirect, render_template, request, url_for
  2. from yird.services.posts import PostsService
  3. from yird.settings import Settings
  4. app = Flask(__name__)
  5. yird_settings = Settings()
  6. @app.route('/admin')
  7. def index():
  8. posts = PostsService.get_posts()
  9. return render_template('index.html.j2', posts=posts)
  10. @app.route('/admin/posts/new')
  11. def new_post():
  12. form = PostsService.get_post_form()
  13. return render_template('posts/form.html.j2', post=False, form=form)
  14. @app.route('/admin/posts', methods=["POST"])
  15. def create_post():
  16. PostsService.create_post(request.form)
  17. return redirect(url_for('index'))
  18. @app.route('/admin/posts/<post_id>')
  19. def edit_post(post_id):
  20. post = PostsService.get_post(post_id)
  21. form = PostsService.get_post_form(post)
  22. return render_template('posts/form.html.j2', post=post, form=form)
  23. @app.route('/admin/posts/<post_id>', methods=["POST"])
  24. def update_post(post_id):
  25. PostsService.update_post(post_id, request.form)
  26. return redirect(url_for('index'))
  27. @app.route('/admin/generate')
  28. def generate():
  29. PostsService.generate_posts()
  30. return redirect(url_for('index'))
  31. if __name__ == "__main__":
  32. app.run(debug=True)