๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐ŸŒŒ | WEB DEV115

JS_๊ธฐ๋ณธ ๋ฌธ๋ฒ• (15)_์—ฐ์‚ฐ์ž(์‰ผํ‘œ, null๋ณ‘ํ•ฉ(??) ) ์ง€๊ธˆ๊นŒ์ง€ ์‚ดํŽด๋ณธ ๊ฒƒ ์™ธ์˜ ์—ฐ์‚ฐ์ž๋“ค์— ๋Œ€ํ•ด์„œ๋„ ์•Œ์•„๋ณด์ž! 1. ์‰ผํ‘œ ์—ฐ์‚ฐ์ž ์™ผ์ชฝ๋ถ€ํ„ฐ ์ฐจ๋ก€๋กœ ์‹คํ–‰๋˜๋ฉฐ, ๊ฐ€์žฅ ๋งˆ์ง€๋ง‰ ์—ฐ์‚ฐ์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. console.log( (1,2,3) ); >>> 3 console.log( (10/2, 5%2, 1+1) ); >>> 2 ์ด์ฒ˜๋Ÿผ ๊ฐ€์žฅ ๋งˆ์ง€๋ง‰ ์—ฐ์‚ฐ์˜ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค! 2. null ๋ณ‘ํ•ฉ ์—ฐ์‚ฐ์ž ?? null ๋˜๋Š” undefined๋ฅผ ๊ฑธ๋Ÿฌ๋‚ผ ์ˆ˜ ์žˆ๋Š” ์—ฐ์‚ฐ์ž์ด๋‹ค. ์ฆ‰, ์•ž์˜ ์›์†Œ๊ฐ€ ๋‘˜ ์ค‘ ํ•˜๋‚˜์ผ ๊ฒฝ์šฐ ๋’ค์˜ ์›์†Œ๋กœ ๋Œ€์ฒด๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค! let x;//undefined x ?? console.log('Hello'); x = null;//null x ?? console.log('Hello'); x = 0; x ?? console.log('Hello'); //0์„ ๋ฐ˜ํ™˜ํ•˜๊ณ  ์ข…๋ฃŒ x = 1;.. 2023. 2. 26.
JS_๊ธฐ๋ณธ ๋ฌธ๋ฒ• (14)_๋ถˆ๋ฆฌ์–ธ์— ์‚ฌ์šฉ๋˜๋Š” ์—ฐ์‚ฐ์ž๋“ค ๋ถˆ๋ฆฌ์–ธ(boolean)์— ๊ด€๋ จ๋œ ์—ฐ์‚ฐ์ž๋“ค์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด์ž! let a = 1 === 2;//false let b = 'abc' !== 'def'//true let c = a !== b;//true let d = typeof a === typeof b === true;//true 4๋ฒˆ์งธ ์˜ˆ์‹œ์™€ ๊ฐ™์ด ์—ฐ์† ๋น„๊ต ์‹œ์—๋Š” ์šฐ์„ ์ˆœ์œ„์— ๋”ฐ๋ผ ์—ฐ์‚ฐ์ด ๋œ๋‹ค. (ํ•ด๋‹น ์˜ˆ์‹œ๋Š” ๊ฐ™์€ ์šฐ์„ ์ˆœ์œ„ ์ด๋ฏ€๋กœ ์•ž์˜ ์—ฐ์‚ฐ์ด ๋จผ์ €) 1. ์—ฐ์‚ฐ์ž 1) ๋ถ€์ • ์—ฐ์‚ฐ์ž ! ๋ฅผ ์ด์šฉํ•ด NOT ์—ฐ์‚ฐ์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค. !true //false !!true//true ์ด๋•Œ !!๋กœ ๋‘๊ฐœ๋ฅผ ๋ถ™์ผ ๊ฒฝ์šฐ !๊ฐ€ ์„œ๋กœ ์น˜ํ™˜๋˜๋Š”๋ฐ ์ด๋ฅผ ์ด์šฉํ•˜์—ฌ ํ˜„์žฌ ๊ฐ’์„ boolean ๊ฐ’์œผ๋กœ ๋ณ€ํ™˜ ํ•  ์ˆ˜ ์žˆ๋‹ค. console.log(!!'a') >>> true 2) AND O.. 2023. 2. 26.
JS_๊ธฐ๋ณธ ๋ฌธ๋ฒ• (13)_์ˆซ์ž์— ์‚ฌ์šฉ๋˜๋Š” ์—ฐ์‚ฐ์ž๋“ค ์ˆซ์ž์™€ ๊ด€๋ จ๋œ ์—ฐ์‚ฐ์ž๋“ค์„ ์•Œ์•„๋ณด์ž! 1. ์ˆซ์ž ์ž๋ฃŒํ˜• number 1) ์–‘๊ณผ ์Œ JS์—์„œ๋Š” ์ •์ˆ˜์™€ ์‹ค์ˆ˜ ๋ชจ๋‘ number ์ž๋ฃŒํ˜•์ด๋‹ค. ์ฆ‰, ์ •์ˆ˜๋„ ๋‚ด๋ถ€์—์„œ ์‹ค์ˆ˜๋ฅผ ํ‘œํ˜„ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์ฒ˜๋ฆฌ๋œ๋‹ค. + ์™€ -๋กœ ์–‘๊ณผ ์Œ์„ ๋‚˜ํƒ€๋‚ธ๋‹ค! 2) ๋ฌดํ•œ๋Œ€ Infinity ๋Š” ๋ฌดํ•œ๋Œ€๋ฅผ ํ‘œํ˜„ํ•˜๋Š” ์ž๋ฃŒํ˜•์œผ๋กœ number์˜ ๋ฒ”์ฃผ์— ์†ํ•œ๋‹ค. ์ด ๋˜ํ•œ ์–‘๊ณผ ์Œ์ด ์กด์žฌํ•œ๋‹ค. 3) NaN Not a Number์˜ ์•ฝ์ž๋กœ ์ˆซ์ž๊ฐ€ ์•„๋‹Œ ๊ฒƒ์„ ์˜๋ฏธํ•œ๋‹ค. NaN ์—ญ์‹œ number์˜ ๋ฒ”์ฃผ์— ์†ํ•œ๋‹ค. let x = 1 / 'a'; let y = 2 * 'a'; let z = NaN; console.log(x, typeof x); console.log(y, typeof y); console.log(z, typeof z); >>> NaN 'numbe.. 2023. 2. 26.
JS_๊ธฐ๋ณธ ๋ฌธ๋ฒ• (12)_๋ฌธ์ž์—ด์— ์‚ฌ์šฉ๋˜๋Š” ์—ฐ์‚ฐ์ž๋“ค ๋ฌธ์ž์—ด์— ์‚ฌ์šฉ๋˜๋Š” ์—ฐ์‚ฐ์ž๋“ค์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์ž! 1. ๋น„๊ต ์—ฐ์‚ฐ์ž ์—ฐ์‚ฐ์ž ์˜๋ฏธ x == y ๊ฐ’์ด ๊ฐ™์Œ x === y ์ž๋ฃŒํ˜•๊ณผ ๊ฐ’์ด ๊ฐ™์Œ x != y ๊ฐ’์ด ๋‹ค๋ฆ„ x !== y ์ž๋ฃŒํ˜• ๋˜๋Š” ๊ฐ’์ด ๋‹ค๋ฆ„ x = y ์‚ฌ์ „ ์ˆœ ์ƒ์œผ๋กœ y๊ฐ€ ๋จผ์ € ์˜ค๊ฑฐ๋‚˜ ๊ฐ™์Œ console.log('1' == 1, '1' === 1); >> true false == ์€ ์ž๋ฃŒํ˜•์„ ๊ณ ๋ คํ•˜์ง€ ์•Š์ง€๋งŒ ===์€ ์ž๋ฃŒํ˜•์„ ๊ณ ๋ คํ•œ๋‹ค. ๋”ฐ๋ผ์„œ ===๊ณผ !==์„ ๊ถŒ์žฅํ•œ๋‹ค! console.log( 'A' >> true true false ๋น„๊ต ์—ฐ์‚ฐ์ž๋ฅผ ์ด์šฉํ•  ๊ฒฝ์šฐ ์‚ฌ์ „ ์ƒ์˜ ์ˆœ์„œ๋ฅผ ๊ณ ๋ คํ•œ๋‹ค. ์ด๋•Œ ๋Œ€๋ฌธ์ž๊ฐ€ ์†Œ๋ฌธ์ž๋ณด๋‹ค ๋น ๋ฅด๋‹ค. ์ˆซ์ž ๋ฌธ์ž์—ด์˜ ๋น„๊ต.. 2023. 2. 26.
JS_๊ธฐ๋ณธ ๋ฌธ๋ฒ• (11)_ํ…œํ”Œ๋ฆฟ ๋ฌธ์ž์—ด JS์—์„œ ๋ฌธ์ž์—ด ๋‚ด์˜ ์ผ์ •ํ•œ ํ‹€(template)์„ ์ด์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์ž. ๋ณ€์ˆ˜์— ์ €์žฅ๋œ ๊ฐ’์„ ์‚ฝ์ผํ•  ์ˆ˜ ์žˆ๋‹ค. let name = 'KASSID' let month = 11 let day = 23 console.log(`${name}๋‹˜์˜ ๋“ฑ๋ก์ผ์€ ${month}์›” ${day}์ผ ์ž…๋‹ˆ๋‹ค.`) -------- KASSID๋‹˜์˜ ๋“ฑ๋ก์ผ์€ 11์›” 23์ผ ์ž…๋‹ˆ๋‹ค. ํ•จ์ˆ˜๊ฐ’์„ ๋ฐ”๋กœ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. let num = 3; let getTwice = (x)=>{ return x * 2 } console.log(`${num}์˜ ๋‘ ๋ฐฐ๋Š” ${getTwice(num)}`) -------- 3์˜ ๋‘ ๋ฐฐ๋Š” 6 2022. 11. 23.
JS_๋ฌธ๋ฒ• (10)_๋Œ€ํ™”์ฐฝ ๋Œ€ํ™”์ฐฝ์— ์‚ฌ์šฉ์ž์™€ ์ƒํ˜ธ์ž‘์šฉํ•  ์ˆ˜ ์žˆ๋Š” ํ•จ์ˆ˜๋“ค์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด์ž! prompt() ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ๋ฌธ์ž์—ด ์ž…๋ ฅ์„ ๋ฐ›๋Š” ํ•จ์ˆ˜์ด๋‹ค. ์ด๋ฅผ parseInt()์™€ ๊ฐ™์€ ํ•จ์ˆ˜๋กœ ํ˜•๋ณ€ํ™˜ํ•˜์—ฌ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. prompt("๋Œ€ํ™”์ฐฝ ๋ฉ”์„ธ์ง€"); const num = prompt("์ด๋ฆ„์„ ์ž…๋ ฅํ•˜์„ธ์š”"); const num = parseInt(prompt("์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”")); alert() ์‚ฌ์šฉ์ž์—๊ฒŒ ๊ฒฝ๊ณ ์ฐฝ์„ ๋„์šฐ๋Š” ํ•จ์ˆ˜์ด๋‹ค. alert("๋Œ€ํ™”์ฐฝ ๋ฉ”์„ธ์ง€"); alert("Hello!"); confirm() ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ Y/N์„ ๋ฐ›๋Š” ํ•จ์ˆ˜์ด๋‹ค. confirm("๋Œ€ํ™”์ฐฝ ๋ฉ”์„ธ์ง€"); const yesNo = confirm(num+" ๋ช…์ด ๋งž์Šต๋‹ˆ๊นŒ?"); //script์˜ ๋ณ€์ˆ˜๋ฅผ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. 2022. 7. 26.
Django_์žฅ๊ณ  ๋ถ€์ˆ˜๊ธฐ (7)_login, logout ๋กœ๊ทธ์ธ/์•„์›ƒ ๊ตฌํ˜„ 1. urls.py ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์— ์ข…์†๋˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ฏ€๋กœ ํ”„๋กœ์ ํŠธ์˜ urls.py์— ํŒจํ„ด์„ ์ถ”๊ฐ€ํ•œ๋‹ค. from django.contrib import admin from django.urls import include, path from django.contrib.auth import views urlpatterns = [ path(r'^admin/', admin.site.urls), path(r'^accounts/login/$', views.LoginView.as_view(template_name="registration/login.html"), name='login'), path(r'^accounts/logout/$', views.LogoutView.as_view(template_n.. 2022. 6. 30.
Django_์žฅ๊ณ  ๋ถ€์ˆ˜๊ธฐ (6)_CRUD CRUD (Create Read Update Delete) ์ƒ์„ฑ, ์ฝ๊ธฐ, ์ˆ˜์ •, ์‚ญ์ œ๊ฐ€ ๊ฐ€๋Šฅํ•œ ํŽ˜์ด์ง€๋ฅผ ๊ตฌํ˜„ํ•ด๋ณด์ž Form CRUD๋ฅผ ์œ„ํ•ด์„œ ํ•„์š”ํ•œ ํƒœ๊ทธ์ด๋‹ค. ์ด ํƒœ๊ทธ๋ฅผ ์ด์šฉํ•ด์„œ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค. ์ด๋ฅผ ์ด์šฉํ•˜์—ฌ ์–‘์‹์„ ๋งŒ๋“ค์–ด ๋‚ด๊ธฐ๋„ ํ•˜๊ณ , ์ž…๋ ฅ๋ฐ›์€ ๋ฐ์ดํ„ฐ๋กœ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•ด๋‚ผ ์ˆ˜๋„ ์žˆ๋‹ค. 1. forms.py ์ƒ์„ฑ - ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋””๋ ‰ํ† ๋ฆฌ ๋‚ด์— ํ•ด๋‹น ํŒŒ์ผ์„ ์ƒ์„ฑํ•œ๋‹ค. - form ๋ชจ๋ธ์„ ์žฅ๊ณ ๋กœ๋ถ€ํ„ฐ ๊ฐ€์ ธ์˜ค๊ณ , ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์›ํ•˜๋Š” ๋ชจ๋ธ์„ ๊ฐ€์ ธ์™€์•ผํ•œ๋‹ค. ์˜ˆ์‹œ from django import forms from .models import Post class PostForm(forms.ModelForm): class Meta: model = Post fields = ('title', 'text',) -.. 2022. 6. 30.
Django_์žฅ๊ณ  ๋ถ€์ˆ˜๊ธฐ (5)_ํŽ˜์ด์ง€ ์ด๋™, ์ƒ์„ธ ํŽ˜์ด์ง€ ํŽ˜์ด์ง€ ์ด๋™ ๋ธŒ๋ผ์šฐ์ €๋กœ๋ถ€ํ„ฐ request๋ฅผ ๋ฐ›๊ณ  ์ ์ ˆํ•œ url์„ ์—ฐ๊ฒฐ์‹œ์ผœ์ฃผ์–ด์•ผ ํ•œ๋‹ค. urls.py) - urlํŒจํ„ด์— path๋ฅผ ์ถ”๊ฐ€ํ•ด์ค€๋‹ค. path('url๊ฒฝ๋กœ', views.ํ•จ์ˆ˜๋ช…, name='ํ…œํ”Œ๋ฆฟ ํƒœ๊ทธ์— ์“ฐ์ผ ์ด๋ฆ„') ์˜ˆ์‹œ path('post_list', views.post_list, name='post_list'), 'main๋ฃจํŠธ/post_lis't๊ฐ€ url ๊ฒฝ๋กœ๊ฐ€ ๋œ๋‹ค. views.py) request ๋“ฑ์˜ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ „๋‹ฌ ๋ฐ›์€ ๊ฒƒ์„ ์ฒ˜๋ฆฌํ•œ ํ›„ render, redirect ๋“ฑ์˜ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœ, ๋ฐ˜ํ™˜ํ•œ๋‹ค. template) ํ…œํ”Œ๋ฆฟ์—์„œ๋Š” ํ…œํ”Œ๋ฆฟ ํƒœ๊ทธ๋ฅผ ์ด์šฉํ•ด ํ˜ธ์ถœํ•œ๋‹ค. ๋‚ด์šฉ์€ urls.py์˜ name์— ์ •์˜๋œ ์ด๋ฆ„์„ ์ด์šฉํ•œ๋‹ค. ... ์ƒ์„ธ ํŽ˜์ด์ง€ pk(Primary Key) DB์˜ ๊ฐ ๋ ˆ์ฝ”๋“œ๋ฅผ ์‹.. 2022. 6. 30.
๋ฐ˜์‘ํ˜•