File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ __pycache__
2+ .vscode
3+ flask
Original file line number Diff line number Diff line change 1+ import os
2+ from flask import Flask
3+ from flask import redirect
4+ from flask import request
5+ from flask import render_template
6+ from models import db
7+ from models import Fcuser
8+
9+ app = Flask (__name__ )
10+
11+ @app .route ("/" )
12+ def hello ():
13+ return render_template ('hello.html' )
14+
15+ @app .route ("/register" , methods = ['GET' , 'POST' ])
16+ def register ():
17+ if request .method == 'POST' :
18+ userid = request .form .get ('userid' )
19+ username = request .form .get ('username' )
20+ password = request .form .get ('password' )
21+ rePassword = request .form .get ('re-password' )
22+
23+ if (userid and username and password and rePassword ) and password == rePassword :
24+ fcuser = Fcuser ()
25+ fcuser .userid = userid
26+ fcuser .username = username
27+ fcuser .password = password
28+
29+ db .session .add (fcuser )
30+ db .session .commit ()
31+
32+ return redirect ('/' )
33+ return render_template ('register.html' )
34+
35+
36+
37+ if __name__ == '__main__' :
38+ basedir = os .path .abspath (os .path .dirname (__file__ ))
39+ dbfile = os .path .join (basedir , 'db.sqlite' )
40+
41+ app .config ['SQLALCHEMY_DATABASE_URI' ] = 'sqlite:///' + dbfile
42+ app .config ['SQLALCHEMY_COMMIT_ON_TEARDOWN' ] = True
43+ app .config ['SQLALCHEMY_TRACK_MODIFICATIONS' ] = False
44+
45+ db .init_app (app )
46+ db .app = app
47+ db .create_all ()
48+ app .run (host = '127.0.0.1' , port = 5000 , debug = True )
Original file line number Diff line number Diff line change 1+ from flask_sqlalchemy import SQLAlchemy
2+
3+ db = SQLAlchemy ()
4+
5+ class Fcuser (db .Model ):
6+ __tablename__ = 'user'
7+ id = db .Column (db .Integer , primary_key = True )
8+ password = db .Column (db .String (64 ))
9+ userid = db .Column (db .String (32 ))
10+ username = db .Column (db .String (8 ))
Original file line number Diff line number Diff line change 1+ Hello World!
Original file line number Diff line number Diff line change 1+ < html >
2+ < head >
3+ < meta charset ="utf-8 ">
4+ < meta name ='viewport ' content ='width=device-width, initial-scale=1, shrink-to-fit=no ' />
5+
6+ < link rel ="stylesheet " href ="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css " integrity ="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T " crossorigin ="anonymous ">
7+
8+ < script src ="https://code.jquery.com/jquery-3.3.1.slim.min.js " integrity ="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo " crossorigin ="anonymous "> </ script >
9+ < script src ="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js " integrity ="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1 " crossorigin ="anonymous "> </ script >
10+ < script src ="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js " integrity ="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM " crossorigin ="anonymous "> </ script >
11+ </ head >
12+
13+ < body >
14+ < div class ="container ">
15+ < div class ="row mt-5 ">
16+ < h1 > 회원가입</ h1 >
17+ </ div >
18+ < div class ="row mt-5 ">
19+ < div class ="col-12 ">
20+ < form method ="POST ">
21+ < div class ="form-group ">
22+ < label for ="userid "> 아이디</ label >
23+ < input type ="text " class ="form-control " id ="userid " placeholder ="아이디 " name ="userid "/>
24+ </ div >
25+ < div class ="form-group ">
26+ < label for ="username "> 사용자 이름</ label >
27+ < input type ="text " class ="form-control " id ="username " placeholder ="사용자 이름 " name ="username "/>
28+ </ div >
29+ < div class ="form-group ">
30+ < label for ="password "> 비밀번호</ label >
31+ < input type ="password " class ="form-control " id ="password " placeholder ="비밀번호 " name ="password "/>
32+ </ div >
33+ < div class ="form-group ">
34+ < label for ="re-password "> 비밀번호 확인</ label >
35+ < input type ="password " class ="form-control " id ="re-password " placeholder ="비밀번호 확인 " name ="re-password "/>
36+ </ div >
37+ < button type ="submit " class ="btn btn-primary "> 등록</ button >
38+ </ form >
39+ </ div >
40+ </ div >
41+ </ div >
42+ </ body >
43+ </ html >
You can’t perform that action at this time.
0 commit comments