@app.post("/notes/", response_model=Note)
async def create_note(note: NoteIn):
query = notes.insert().values(text=note.text, completed=note.completed)
last_record_id = await database.execute(query)
return {**note.dict(), "id": last_record_id}
for rowm, index in range(len(mls_scc)):
if row['gender'] == "M":
input_ssc_level = rd[rowm[1][0][index]].value
name = request.form["username"]
<input type="text" name = "username" blablabla >
from fastapi import FastAPI
app = FastAPI()
@app.get("/dialog/")
def read_item(message: str, lang: str = 'ru'):
return {'message': detect_intent_texts(TOKEN, SESSION_ID, message, lang)
document.querySelector("#button").addEventListener("click", (event) => {
const msg = document.querySelector("#message").value;
const lang = document.querySelector("#lang").value;
fetch('/dialog/?' + new URLSearchParams({
message: msg,
lang: lang,
}))
.then((response) => {
if (!response.ok) {
throw new Error("HTTP error, status = " + response.status);
}
return response.json();
})
.then((data) => {
alert(data.message);
})
.catch((error) => {
alert(error);
});
});
document.getElementById("myForm").addEventListener('submit', (event) => {
const data = new FormData(event.target);
if(!formValid(data)) {
event.preventDefault(); // отменяем action формы
return;
}
})
document.getElementById("myForm").addEventListener('submit', (event) => {
const data = new FormData(event.target);
fetch("/register", {
method: 'POST',
body: data
})
.then((response) => response.json())
.then((data) => {
// тут рисуешь алерты в DOM
})
.catch((error) => {
console.log(`fetch.post response came up with an error: ${error}`);
});
event.preventDefault();
})
if request.method == 'POST':
data = request.form
ok, err = validateForm(data)
if not ok:
return jsonify(err)
DoRegisterUser(data)
return redirect(url_for(index))