JAVASCRIPT&JQUERY

자바스트립트 토글버튼 만들기 (파이썬)

9400 2023. 1. 10. 14:12

파이썬시간

파이썬 fastapi설정해주고 

 

from fastapi import FastAPI,Form,Request
from fastapi.templating import Jinja2Templates
from fastapi.staticfiles import StaticFiles
from fastapi.responses import HTMLResponse
import pymssql
import uvicorn

app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="static")

templates = Jinja2Templates(directory="templates")

@app.get("/")
@app.get("/hello", response_class=HTMLResponse)
async def forw(request: Request):
    return templates.TemplateResponse("hello.html", {"request": request})

if __name__ == "__main__":
    uvicorn.run(app, host="localhost", port=8000)

 

 

ex01.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">

function myclick(){
	var obj = document.querySelector('#myspan');
/* 	console.log("obj");
	obj.innerHTML = "Good Evening"; */
	
	if(obj.innerText=="Good Morning"){
		obj.innerText = "Good Evening";
	}else{
		obj.innerText="Good Morning";
	}
}


</script>
</head>
<body>
<span id="myspan">Good Morning</span>
<input type="button" onclick="myclick()" value="click" />
</body>
</html>

 

서버실행 후 

http://localhost:8000/static/ex01.html 

 

출력성공