portfolio-website/project/portfolio/routes.py

29 lines
979 B
Python
Raw Permalink Normal View History

from . import portfolio_blueprint
2022-07-13 06:28:07 +00:00
from flask import render_template, abort, send_from_directory
from os import listdir
import os
2022-07-13 05:15:23 +00:00
categories = ['residential', 'commercial', 'office', 'industrial']
@portfolio_blueprint.route('/')
def index():
2022-07-13 05:15:23 +00:00
return render_template('index.html')
2022-07-13 06:28:07 +00:00
@portfolio_blueprint.route('/portfolio/')
2022-07-13 05:15:23 +00:00
def gallery():
2022-07-13 06:28:07 +00:00
photos = listdir('portfolio/residential')
return render_template('gallery.html', photos=photos)
def photo_generator():
for photo in listdir('portfolio/residential'):
path = photo
yield ('show_photo', {'category':'residential', 'filename':path})
@portfolio_blueprint.route('/portfolio/<category>/<path:filename>')
def show_photo(category, filename):
root_dir = os.getcwd()
# print(os.getcwd())
# print(os.path.join(os.getcwd(), 'portfolio', category, filename))
# print(listdir('portfolio/residential'))
return send_from_directory(os.path.join(root_dir, 'portfolio', category), filename)