68 lines
1.7 KiB
Python
68 lines
1.7 KiB
Python
from flask import Flask, render_template, abort
|
|
from comics_data import COMICS
|
|
|
|
app = Flask(__name__)
|
|
|
|
# Configuration
|
|
app.config['SECRET_KEY'] = 'your-secret-key-here' # Change this in production
|
|
|
|
|
|
def get_comic_by_number(number):
|
|
"""Get a comic by its number"""
|
|
for comic in COMICS:
|
|
if comic['number'] == number:
|
|
return comic
|
|
return None
|
|
|
|
|
|
def get_latest_comic():
|
|
"""Get the most recent comic"""
|
|
if COMICS:
|
|
return COMICS[-1]
|
|
return None
|
|
|
|
|
|
@app.route('/')
|
|
def index():
|
|
"""Home page - shows latest comic"""
|
|
comic = get_latest_comic()
|
|
if not comic:
|
|
return render_template('index.html', title='Latest Comic',
|
|
comic=None, total_comics=0)
|
|
return render_template('index.html', title='Latest Comic',
|
|
comic=comic, total_comics=len(COMICS))
|
|
|
|
|
|
@app.route('/comic/<int:comic_id>')
|
|
def comic(comic_id):
|
|
"""View a specific comic"""
|
|
comic = get_comic_by_number(comic_id)
|
|
if not comic:
|
|
abort(404)
|
|
return render_template('comic.html', title=f"Comic #{comic_id}",
|
|
comic=comic, total_comics=len(COMICS))
|
|
|
|
|
|
@app.route('/archive')
|
|
def archive():
|
|
"""Archive page showing all comics"""
|
|
# Reverse order to show newest first
|
|
comics = list(reversed(COMICS))
|
|
return render_template('archive.html', title='Archive',
|
|
comics=comics)
|
|
|
|
|
|
@app.route('/about')
|
|
def about():
|
|
"""About page"""
|
|
return render_template('about.html', title='About')
|
|
|
|
|
|
@app.errorhandler(404)
|
|
def page_not_found(e):
|
|
"""404 error handler"""
|
|
return render_template('404.html', title='Page Not Found'), 404
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app.run(debug=True, port=3000) |