PROJECTS

Django | ๋กœ๊ทธ์•„์›ƒ

nicesugi 2022. 5. 31. 15:34

 

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป Github

https://github.com/nicesugi/DjangoClass/tree/main/sns

 

 logout html&function + link urls


 

๋กœ๊ทธ์•„์›ƒ ๊ตฌํ˜„

1. user/views.py 

๋กœ๊ทธ์•„์›ƒ์€ ๋กœ๊ทธ์ธ์ด ๋˜์–ด ์žˆ๋Š” ์ƒํƒœ์—์„œ ํ•  ์ˆ˜ ์žˆ์œผ๋‹ˆ ์žฅ๊ณ ์˜ decorator๋ฅผ ์ž„ํฌํŠธ๋ฅผ ์‚ฌ์šฉํ•ด์ค๋‹ˆ๋‹ค

contrib.auth.decorators ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ์—์„œ login_required ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ์ œํ•œ๋œ ์ƒํ™ฉ์—์„œ๋งŒ ์ž‘๋™ํ•˜๋ฉฐ,

ํ•จ์ˆ˜(์ฒซ ๋ฒˆ์งธ ์ธ์ˆ˜๊ฐ€ 'request'์ธ ๊ฒฝ์šฐ)์™€ ๋ฉ”์„œ๋“œ(์ฒซ ๋ฒˆ์งธ ์ธ์ˆ˜๊ฐ€ 'self'์ด๊ณ  ๋‘ ๋ฒˆ์งธ ์ธ์ˆ˜๊ฐ€ 'request'์ธ ๊ฒฝ์šฐ) ๋ชจ๋‘์—์„œ ์ด๋Ÿฌํ•œ ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

 

'/'๋กœ ์ด๋™ํ•˜๋Š” ์ด์œ ๋Š” tweet.views์— home ํ•จ์ˆ˜์—์„œ ์ž๋™์œผ๋กœ ์กฐ๊ฑด์— ๋งž๋Š” ํŽ˜์ด์ง€๋กœ ์ด๋™ํ•˜๊ธฐ ๋•Œ๋ฌธ

home ํ•จ์ˆ˜๋Š” tweet or sign-in ๋กœ redirectํ•ด์คŒ

contrib.auth.decorators

 

 

2. user/urls.py

user/urls.py

 

 

3. base.html 

base.html 9๋ฒˆ ์ถ”๊ฐ€

 

๋ฐ˜์‘ํ˜•