0831 SeSAC(새싹) 3기 12일차
value값으로 불러오면 항상 문자열로 불러진다.
문자였을땐 공란이면 F
숫자 0는 f/ 1은 t
어퍼스트로피 ’ (` 이건가?) 안에 변수랑 문자열 같이 넣을 수 있는데 변수는 ${}안에 묶고
장고 관리자
root
qa2213886*
https://www.djangoproject.com/
https://docs.djangoproject.com/ko/3.2/topics/db/models/
모델은 데이터베이스, 유저라는 테이블이 있어.
from django.db import models
class Person(models.Model):
SHIRT_SIZES = (
('S', 'Small'),
('M', 'Medium'),
('L', 'Large'),
)
name = models.CharField(max_length=60)
shirt_size = models.CharField(max_length=1, choices=SHIRT_SIZES)
>>> p = Person(name="Fred Flintstone", shirt_size="L")
>>> p.save() //db에 삽입
>>> p.shirt_size
'L'
>>> p.get_shirt_size_display()
'Large'
{% for member in totoal_member %}
{{member.userid}}
{% endfor %}
total_member에 있는 멤버를 하나 하나씩 불러온다.
{% for member in total_member %}
아이디 : {{ member.userid }}<br>
이름 : {{ member.username }}<br>
<br>
<br>
<br>
{% endfor %}
User.objects.filter(username=req.POST.get('id'), password=req.POST.get('pw'));
-> id가 이렇고 pw가 이런 멤버가 있으면(인풋창에 입력해서) //데이터베이스 안에// 로그인이 성공된다.
def logged(req):
logged_member = User.objects.filter(userid=req.POST.get('id'),password=req.POST.get('pw'))
if logged_member :
print("로그인성공")
else :
print("로그인실패")
실습
회원가입 및 로그인 기능 구현!!
검사 맡아야 집에 갈 수 있음
http://27.96.135.73:8000/yookeunbyul/join
http://27.96.135.73:8000/yookeunbyul/login
#member.urls.py
from django.urls import path
from . import views
urlpatterns = [
path('join', views.join),
path('joined', views.joined),
path('login', views.login ),
path('logged', views.logged ),
]
#member.views.py
from django.shortcuts import render
from .models import User #모델불러오려면 필수
# Create your views here.
def join ( req ) :
return render ( req, 'join.html' )
def joined ( req ) :
new_member = User( username = req.POST.get('name'), userid = req.POST.get('id'), password = req.POST.get('pwd'), gender = req.POST.get('gender') )
new_member.save() #데이터베이스에 저장
return render ( req, 'joined.html' )
def login( req ) :
return render( req, 'login.html' )
def logged( req ) :
logged_member = User.objects.filter(userid=req.POST.get('id'), password=req.POST.get('pwd')) #필터링
if logged_member :
print("로그인 성공")
return render( req, 'logged.html' )
else :
print("로그인 실패")
return render( req, 'unlogged.html' )
#join.html
<html>
<head>
<title>회원가입</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<form action="http://27.96.135.73:8000/yookeunbyul/joined" method="post">
{% csrf_token %}
<div class="input-group flex-nowrap my-3">
<div class="input-group-prepend">
<span class="input-group-text" id="addon-wrapping">name</span>
</div>
<input type="text" class="form-control" placeholder="Username" name='name'>
</div>
<div class="input-group flex-nowrap my-3">
<div class="input-group-prepend">
<span class="input-group-text" id="addon-wrapping">id</span>
</div>
<input type="text" class="form-control" placeholder="Userid" name='id'>
</div>
<div class="input-group flex-nowrap my-3">
<div class="input-group-prepend">
<span class="input-group-text" id="addon-wrapping">password</span>
</div>
<input type="text" class="form-control" placeholder="Userpwd" name='pwd'>
</div>
<div class="input-group my-3">
<div class="input-group-prepend">
<label class="input-group-text" for="inputGroupSelect01">gender</label>
</div>
<select class="custom-select" id="inputGroupSelect01" name='gender'>
<option selected>gender</option>
<option value="M">남성</option>
<option value="W">여성</option>
</select>
</div>
<button type="submit" class="btn btn-primary my-3">회원가입</button>
</form>
</div>
</body>
</html>
#joined.html
<html>
<head>
<title>회원가입 성공</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<div class="text-center my-3">회원가입을 축하합니다</div>
<div class="text-center">
<a href="http://27.96.135.73:8000/yookeunbyul/login">
<button type="button" class="btn btn-warning">로그인하러가기</button>
</a>
</div>
</div>
</body>
</html>
#login.html
<html>
<head>
<title>로그인</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<form action="http://27.96.135.73:8000/yookeunbyul/logged" method="post">
{% csrf_token %}
<div class="input-group flex-nowrap my-3">
<div class="input-group-prepend">
<span class="input-group-text" id="addon-wrapping">id</span>
</div>
<input type="text" class="form-control" placeholder="Userid" name='id'>
</div>
<div class="input-group flex-nowrap my-3">
<div class="input-group-prepend">
<span class="input-group-text" id="addon-wrapping">password</span>
</div>
<input type="text" class="form-control" placeholder="Userpwd" name='pwd'>
</div>
<button type="submit" class="btn btn-primary">로그인</button>
</form>
</div>
</body>
</html>
#logged.html
<html>
<head>
<title>로그인 성공</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>
</head>
<body>
<div class="container my-3">
<div class="text-center">로그인을 성공하였습니다</div>
</div>
</body>
</html>
#unlogged.html
<html>
<head>
<title>로그인 실패</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>
</head>
<body>
<div class="container my-3">
<div class="text-center">로그인을 실패하였습니다</div>
</div>
</body>
</html>
Author And Source
이 문제에 관하여(0831 SeSAC(새싹) 3기 12일차), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@gordthemun/0831-SSAC싹-3기-12일차저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)