a part of the website doesn't work, but works when used separately
so this is a code i wrote a while back
it works when i use it in another empty project
im using flask and sqlite3
the html loads but when i use the add or update function it goes to the 'Method Not Allowed The method is not allowed for the requested URL' page
i first though that its not getting in touch with the data base but there seems to be nothing wrong with it connecting
then i though its a vpn problem, but it wasnt that either
i tried rewriting the code manully but that didnt change anything this is the entire website code
from flask import Flask, request, render_template, redirect
from flask_sqlalchemy import SQLAlchemy
import os
import re
import sqlite3
from datetime import datetime
app = Flask(__name__)
project_dir = os.path.dirname(os.path.abspath(__file__))
database_file = "sqlite:///{}".format(os.path.join(project_dir, "todo.db"))
app.config["SQLALCHEMY_DATABASE_URI"] = database_file
db = SQLAlchemy(app)
conn = sqlite3.connect('todo.db', check_same_thread=False)
c = conn.cursor()
class Note(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
text = db.Column(db.Text)
list2 =db.Column(db.Text)
list3 = db.Column(db.Text)
done = db.Column(db.Boolean)
dateAdded = db.Column(db.DateTime, default=datetime.now())
def create_note(first, last, phone):
note = Note(text=f"{first}",list2=f"{last}",list3=f"{phone}")
db.session.add(note)
db.session.commit()
db.session.refresh(note)
var_1 = request.form.get("var_1", type=int, default=0)
print(var_1)
def read_notes():
var_1 = request.form.get("var_1", type=str, default='0')
if var_1 == '0':
return db.session.query(Note).all()
if var_1 == '':
return db.session.query(Note).all()
elif var_1 != '0':
return Note.query.filter_by(text=var_1)
def update_note(note_id, first, last, phone, done):
db.session.query(Note).filter_by(id=note_id).update({
"text": first,
"list2": last,
"list3":phone,
"done": True if done == "on" else False
})
db.session.commit()
def delete_note(note_id):
db.session.query(Note).filter_by(id=note_id).delete()
db.session.commit()
@app.route("/")
def view_index():
return render_template("index.html")
@app.route("/home")
def home():
return render_template("home.html")
@app.route("/artist", methods=['GET', 'POST'])
def artist():
conn = sqlite3.connect('todo.db', check_same_thread=False)
c = conn.cursor()
if request.method == "POST":
first_name = request.form['text']
last_name = name = request.form['text2']
phone_number = request.form['text3']
create_note(first_name, last_name, phone_number)
return render_template("artist.html", notes=read_notes())
@app.route("/edit/<note_id>", methods=['GET', 'POST'])
def edit_note(note_id):
conn = sqlite3.connect('todo.db', check_same_thread=False)
c = conn.cursor()
if request.method == "POST":
update_note(note_id, first=request.form['text'], last=request.form['list2'], phone=request.form['list3'], done=request.form['done'])
elif request.method == "GET":
delete_note(note_id)
return redirect("/artist", code=302)
@app.route("/thepostroute", methods=["POST"])
def v2iew_index():
return render_template("artist.html", notes=read_notes())
@app.route("/customer")
def customer():
return render_template("customer.html")
@app.route("/help")
def Help():
return render_template("Help.html")
@app.route('/home', methods=['POST',"GET"])
def calculator():
conn = sqlite3.connect('customer_service.db', check_same_thread=False)
c = conn.cursor()
var_1 = request.form.get("var_1", type=int, default=0)
var_3 = request.form.get("var_1", type=int, default=0)
var_2 = request.form.get("var_2", type=str, default=0)
def is_discord_username(string) -> bool:
return re.match(r'^[a-zA-Z0-9]#[0-9]{4}$', string) is not None
is_discord_username(var_2)
operation = request.form.get("operation")
operation2 = request.form.get("operation2")
operation3 = request.form.get("operation3")
var_1 = var_1 * 5
contain = '#'
if(operation == 'Low'):
light_price = 15
result = var_1 + light_price
elif(operation == 'Mid'):
light_price = 25
result = var_1 + light_price
elif(operation == 'High'):
light_price = 35
result = var_1 + light_price
else:
result = 'invaild inputs'
if(operation2 == 'custom'):
result = result + 20
elif (operation2 == 'ingame animation'):
result = result + 10
elif (operation2 == 'already made by you'):
result = result + 10
if(operation3 == 'rain'):
result = result + 20
elif (operation3 == 'snow'):
result = result + 15
elif (operation3 == 'none'):
result = result + 0
oorder = (var_1,operation,operation2,operation3)
entry = result
Resulllt = str(var_3) + ',' + operation + ',' + operation2 + ',' + operation3
c.execute("insert into customer_orders(discord_username,order1,price)VALUES ('{}','{}','{}');".format(var_2,Resulllt, result))
conn.commit()
return render_template('home.html', entry=entry)
if __name__ == "__main__":
db.create_all()
app.run(debug=True)
this is the html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Calculator</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">
</head>
<body align=center>
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4"><legend><h1>CALCULATOR</h1></legend></div>
<div class="col-md-4"></div>
</div>
<br>
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4">
<form class="form-horizontal" method="post">
<div class="form-group">
<label class="control-label col-xs-3" for="var_2">discord username:</label>
<div class="col-xs-7">
<input type="q1" class="form-control" name="var_2" value="{{ request.form['var_2'] }}" placeholder=" example#0000 ">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-3" for="var_1">how many characters:</label>
<div class="col-xs-7">
<input type="number" class="form-control" name="var_1" value="{{ request.form['var_1'] }}" placeholder=" 0 ">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-3">light tier:</label>
<div class="col-xs-7">
<select class="form-control" name="operation">
<option>Low</option>
<option>Mid</option>
<option>High</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-3">posing:</label>
<div class="col-xs-7">
<select class="form-control" name="operation2">
<option>custom</option>
<option>ingame animation</option>
<option>already made by you</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-3">weather effects:</label>
<div class="col-xs-7">
<select class="form-control" name="operation3">
<option>snow</option>
<option>rain</option>
<option>none</option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-xs-offset-3 col-xs-9">
<input type="submit" class="btn btn-success" value="Submit">
<input type="reset" class="btn btn-danger" value="Reset">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-3">Result :</label>
<div class="col-xs-7">
<input type="text" name="result" class="form-control" placeholder={{ entry }}>
</div>
</div>
</form>
</div>
<div class="col-md-4"></div></div>
</div>
</body>
</html>