jpscontracting/run_site.py

61 lines
2.0 KiB
Python
Raw Normal View History

from flask import Flask, render_template, send_from_directory
import os
2017-01-12 13:06:39 +00:00
app = Flask(__name__)
@app.route('/')
@app.route('/index')
2017-01-12 13:06:39 +00:00
def index():
categories = os.listdir('projects/')
projects = []
for category in categories:
for project in os.listdir('projects/'+category):
# projects.append(project)
projects.append([category, project, os.listdir('projects/'+category+'/'+project)[0]])
return render_template('index.html', categories=categories, projects=projects)
@app.route('/projects')
@app.route('/projects/')
def show_projects():
categories=os.listdir('projects/')
return render_template('project_category.html', categories=categories)
@app.route('/projects/<category>')
def show_project_category(category):
categories=os.listdir('projects/')
projects = os.listdir('projects/' + category)
print projects
if category in categories:
return render_template('project_category.html', category=category, projects=projects)
else:
return "Error, category not found!"
@app.route('/projects/<category>/<project_name>')
def show_project(category, project_name):
categories=os.listdir('projects')
projects = os.listdir('projects/' + category)
photo_dir = "projects/" + category + '/' + project_name
photos = os.listdir(photo_dir)
if project_name in projects:
return render_template('project.html', category=category, project_name=project_name, photos=photos, photo_dir=photo_dir)
else:
return "Error, project not found!"
@app.route('/projects/<category>/<project_name>/<filename>')
def show_project_file(category, project_name, filename):
return send_from_directory('projects/' + category + '/'+ project_name + '/', filename)
# return 'projects/' + category + '/'+ project_name + '/', filename
2017-01-12 13:06:39 +00:00
2017-01-25 23:07:07 +00:00
@app.route('/about')
def about():
return render_template('aboutus.html', title="Index - JPs")
@app.route('/portfoliio')
def portfolio():
return render_template('index.html', title="Index - JPs")
@app.route('/contact')
def contact():
return render_template('contactus.html', title="Index - JPs")