repl.it
@adriculous/

Female Supervillain Trading Card (template version)

Python

This is the template version of the Female Supervillain Trading Card app. Built using Python, Flask, and Jinja.

fork
loading
Files
  • main.py
  • static
  • templates
  • villain.db
  • Packager files
  • poetry.lock
  • pyproject.toml
  • requirements.txt
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from flask import Flask, render_template, request
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime

app = Flask("app")
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///villain.db"
db = SQLAlchemy(app)

class Villain(db.Model):
  id = db.Column(db.Integer, primary_key=True)
  name = db.Column(db.String(80), unique=True, nullable=False)
  description = db.Column(db.String(250), nullable=False)
  interests = db.Column(db.String(250), nullable=False)
  url = db.Column(db.String(250), nullable=False)
  date_added = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)

  def __repr__(self):
    return "<Villain "+ self.name + ">"

db.create_all()
db.session.commit()

@app.route("/")
def villains_cards():
  return render_template("villain.html", villains=Villain.query.all())

@app.route("/add", methods=["GET"])
def add_villain():
  return render_template("addvillain.html", errors=[])

@app.route("/addVillain", methods=["POST"])
def add_user():
  errors=[]
  name = request.form.get("name", "")
  if not name:
    errors.append("Oops! Looks like you forgot a name!")
  description = request.form.get("description", "")
  if not description:
    errors.append("Oops! Looks like you forgot a description!")
  interests = request.form.get("interests", "")
  if not interests:
    errors.append("Oops! Looks like you forgot some interests!")
  url = request.form.get("url", "")
  if not url:
    errors.append("Oops! Looks like you forgot an image!")
  villain = Villain.query.filter_by(name=name).first()
  if villain:
    errors.append("Oops! A villain with that name already exists!")

  if errors:
    return render_template("addvillain.html", errors=errors)
  else:
    new_villain = Villain(name=name,description=description, interests=interests, url=url)
    db.session.add(new_villain)
    db.session.commit()
    return render_template("villain.html",villains=Villain.query.all())

@app.route("/delete", methods=["GET"])
def delete_villain():
  return render_template("deletevillain.html", errors=[])

@app.route("/deleteVillain", methods=["POST"])
def delete_user():
  name = request.form.get("name")
  villain=Villain.query.filter_by(name=name).first()
  if villain:
    db.session.delete(villain)
    db.session.commit()
    return render_template("villain.html")
  else:
    return render_template("deletevillain.html", errors=["Oops! That villain doesn't exist!"])

app.run(host='0.0.0.0', port=8080)
Fetching token
?