67 lines
2.3 KiB
Python
67 lines
2.3 KiB
Python
from flask import Flask, render_template, send_from_directory
|
|
import os
|
|
|
|
app = Flask(__name__)
|
|
|
|
@app.route('/')
|
|
@app.route('/index')
|
|
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
|
|
|
|
@app.route('/about')
|
|
def about():
|
|
return render_template('aboutus.html', title="Index - JPs")
|
|
|
|
@app.route('/portfolio')
|
|
def portfolio():
|
|
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', title="JPs Contracting - Portfolio", categories=categories, projects=projects)
|
|
|
|
@app.route('/contact')
|
|
def contact():
|
|
return render_template('contactus.html', title="Contact Us - JPs Contracting")
|
|
|