flask website for la petite ecole
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.
 
 
 
 

81 lines
2.5 KiB

from flask import Flask
from flask import render_template, request
from flaskext.markdown import Markdown
from flask_flatpages import FlatPages
import markdown2, os
app = Flask(__name__)
application = app
FLATPAGES_EXTENSION = '.md'
FLATPAGES_MARKDOWN_EXTENSIONS = ['extra']
FLATPAGES_AUTO_RELOAD = True
app.config['APPLICATION_ROOT'] = '/lpe'
app.config.from_object(__name__)
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
app.config.from_object(__name__)
Markdown(app)
pages = FlatPages(app)
pages.get('foo')
def Liste_cat():
articles = (p for p in pages if 'date' in p.meta and 'type' in p.meta and p.meta['type']=='blog')
catList = []
for a in articles:
catList.append(a.meta['category'])
catList = list(dict.fromkeys(catList))
return catList
def imagelist(articlename):
dir_path = os.path.dirname(os.path.realpath(articlename))+'/pages/blog/'
gallery_path = os.path.join(dir_path, articlename)
if os.path.exists(gallery_path):
images = [f for f in os.listdir(gallery_path) if f.endswith('.jpg') or f.endswith('.jpeg') or f.endswith('.png') or f.endswith('.gif')]
return gallery_path ,images
else:
return None, None
@app.route('/')
def index():
infobox = pages.get('info-box')
page = pages.get_or_404('home')
return render_template('home.html' , page=page , infobox=infobox )
@app.route('/home/')
def home():
infobox = pages.get('info-box')
page = pages.get_or_404('home')
return render_template('home.html' , page=page , infobox=infobox )
@app.route('/<path:path>/')
def pageStat(path):
page = pages.get_or_404(path)
return render_template('home.html' , page=page )
@app.route('/pages/<path:path>')
def serve_pages(path):
return send_from_directory('pages', path)
@app.route('/blog/')
def blog():
articles = (p for p in pages if 'date' in p.meta and 'type' in p.meta and p.meta['type']=='blog')
latest = sorted(articles, reverse=True,
key=lambda p: p.meta['date'])
catList = Liste_cat()
return render_template('archive.html', articles=latest , catList=catList )
@app.route('/actu/')
def actu():
articles = (p for p in pages if 'date' in p.meta and 'type' in p.meta and p.meta['type']=='actu')
latest = sorted(articles, reverse=True,
key=lambda p: p.meta['date'])
catList = Liste_cat()
return render_template('archive.html', articles=latest , catList=catList )
if __name__ == '__main__':
app.run(host='0.0.0.0')