Creating Static Page Template
#index.py from flask import render_template from flask_classful import FlaskView, route from models.postdb import Postdb from models.pagedb import Pagedb class Index(FlaskView): @route('/') def index(self): self.postdb = Postdb() vdict = self.postdb.get_post() return render_template('index.html', data=vdict) @route('/post/<id>/') def get_single_post(self, id): self.postdb = Postdb() vdict = self.postdb.get_post(id) return render_template('post.html', data=vdict) @route('/page/<id>/') def get_single_page(self, id): self.pagedb = Pagedb() vdict = self.pagedb.get_page(id) return render_template('page.html', data=vdict) @route('/category/<cat>/') def get_post_category(self, cat): self.postdb = Postdb() vdict = self.postdb.get_post(cat=cat) return render_template('index.html', data=vdict)
#models/pagedb.py import config, copy, lib, requests from flask import render_template from flask_classful import FlaskView, route class Pagedb(): def get_page(self, id=''): vdict = copy.deepcopy(config.vdict) if id: URL = "https://www.googleapis.com/blogger/v3/blogs/"+vdict['blog-id']+"/pages/"+id PARAMS = {"key":vdict['api-key']} r = requests.get(url = URL, params = PARAMS) data = r.json() vdict['page'] = data vdict['id'] = id self.vlib = lib.Lib() vdict['date'] = self.vlib.set_date() return vdict
<!--templates/page.html--> {% extends "base.html" %} {% block head %} {{ super() }} <script src="/static/scripts/page.js"></script> <link href="/static/styles/page.css" rel="stylesheet"> {% endblock %} {% block ad %} <div class="ad region"> <img src="/static/images/ad.jpg" /> </div> <div style="clear: both;"></div> {% endblock %} {% block content %} <div id='content'> {% if 'page' in data %} <h3 class="page-title">{{ data['page']['title'] }}</h3> <div class="meta"> <span class="author">ចុះផ្សាយដោយៈ {{ data['page']['author']['displayName'] }}</span> <span class="date"></span> </div> <div id="page-content">{{ data['page']['content']|safe }}</div> <script> $('#content .date').append(page.toKhDate("{{ data['page']['published'] }}")); </script> {% endif %} <div style="margin-top:20px;" id="disqus_thread"></div> <script> (function() { // DON'T EDIT BELOW THIS LINE var d = document, s = d.createElement('script'); s.src = 'https://khmerweb.disqus.com/embed.js'; s.setAttribute('data-timestamp', +new Date()); (d.head || d.body).appendChild(s); })(); </script> <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> </div> {% endblock %}
/* /static/styles/page.css */ .ad{ padding:0; } .ad img{ width: 100%; margin: 20px 0 0; float: left; } #content{ background: lavender; padding: 20px; } #content .page-title{ font: 22px/1.5 Oswald, Limonf3; } #content .meta{ margin: 20px 0; } #content .meta .date{ float: right; } #content #page-content, #content .description{ font: 17px/1.75 Courgette, HandWriting; font-weight: 600; color: rgb(77, 77, 77) } #content #page-content img{ width: 100%; } #content .description{ margin-top: 10px; }
GitHub: "https://github.com/Sokhavuth/newspaper
Heroku: https://khmerweb-newspaper.herokuapp.com/
Comments
Post a Comment