전체 글
-
Django Auth, Login & LogoutDjango 2024. 8. 17. 06:26
Django Auth auth로 Login, Logout 기능을 구현할 수 있다. 로그인 1. accounts App 생성python manage.py startapp accounts *계정 관련된 로직은 accounts 앱으로 하는 것이 일반적이다.settings.py 가서 앱 등록urls.py 만들기 2. 로그인 구현하기 urls.pyfrom django.urls import pathfrom . import viewsapp_name = "accounts"urlpatterns = [ path("login/", views.login, name="login"),] views.pyfrom django.shortcuts import renderfrom django.contrib.auth.forms imp..
-
Django Form ClassDjango 2024. 8. 17. 03:13
Django Form Class 일부 반복되는 작업 및 코드를 줄일 수 있는 기능으로 Model과 흡사한 형식으로 진행된다.→ 폼에 입력받고 싶은 데이터 형식을 정의한 후, 그렇게 정의해놓은 걸 기준으로 자동으로 폼이 생성되게 해준다. 1) Form 선언하기 articles/ forms.py from django import formsclass ArticleForm(forms.Form): title = forms.CharField(max_length=50) content = forms.CharField() # max_lenth를 지정하지 않으면 길이 제한 없게 입력받는 형식이 됨Model과 비슷하게 이 Form에서 입력받고자 하는 데이터에 대한 내용을 작성한다.형식이나 속성도 일부 Model..
-
Django Model, Migration, ORM, Database APIDjango 2024. 8. 16. 03:07
Django는 Model을 이용해서 데이터를 조작한다.일반적으로 하나의 모델은 하나의 데이터베이스 테이블을 의미한다. 데이터베이스 기본 구조 ↓ User_ID NameEmailAddress1John Doejohn@example.com123 Main St2Jane Doejane@example.com456 Elm St테이블(Table)기본키, PK(Primary Key)열(Column)행(Row) → 이러한 데이터베이스를 Model을 사용해서 구조화 하고 조작할 수 있는데, 장고는 파이썬으로 Model 코드를 작성한 후 데이터베이스에 반영하기 위해 마이그레이션을 만들고, 이 단위로 데이터베이스에 변경사항을 반영한다. Django Model 작성하기 models.py from django.db import ..
-
쿠키와 세션의 차이Computer Science 2024. 8. 14. 10:23
쿠키와 세션을 사용하는 이유?HTTP 프로토콜의 특징이자 약점을 보완하기 위해서 사용한다. 세션과 쿠키는 클라이언트와 서버 간의 상태 정보를 유지하기 위해 사용된다. 하지만 이 둘에는 차이점이 있는데, 세션은 서버 측에서 관리 되고 클라이언트에게는 세션 ID만 전달되지만 쿠키는 클라이언트 측에서 관리된다. 따리서 쿠키는 클라이언트 측에서 변경이 가능하며, 서버가 클라이언트의 요청마다 쿠키를 받아서 처리한다. 쿠키는 클라이언트에서 연결정보를 관리하기 때문에 서버측에서 관리하는 것보다 보안상의 문제가 생길 확률이 높다. 따라서 쿠키보다 세션에서 연결 정보를 관리하는 것이 쿠키보다는 안전하다고 할 수 있다. 하지만 세션만 사용한면 서버에 부하를 줄 수 있기 때문에 이 둘을 적절히 사용하는 것이 중요하다. ..
-
Django HTTP FormDjango 2024. 8. 14. 09:19
Django http form 재밌고 신기하긴한데.. 익숙하지 않아서.. 외울게 많을것같다..🫠많이 많이 연습해야 될것같다..ㅠㅠ 바로 실습해보자.data-throw/ 경로로 들어가면 아래의 data-throw.html 을 보여주는 페이지 작성 Form 작성 Form태그 안에 input요소 넣기 *폼태그 안에 #는 있어도 되고 없어도 된다. 다음으로 넘어가기 전에 input 에서 중요한 점을 알아보자. 📌 input 요소form에서 사용자의 입력을 받기 위해 사용type 속성에 따라 입력 동작 방식이 달라진다.지정하지 않을 경우 type=text로 인식한다. 데이터 전송에서 핵심 속성은 name name으로 서버에 데이터를 전달하고, 서버는 name을 보고 데이터를 판단한다. name의 속성fo..
-
Django Template System (DTL 문법, 템플릿 상속)Django 2024. 8. 13. 03:38
🔖 Django 공식 문서 Django Template Language (DTL)Django Template에서 사용하는 문법으로 Python과 비슷하게 만들어졌다. 하지만 파이썬과 비슷할 뿐 파이썬 코드를 넣으면 동작하지 않으므로 주의해야 한다. DTL 문법 변수, Variable 변수의 기본 형태{{ variable }}view의 context로 넘긴 데이터를 접근할 수 있음. 을 사용하여 변수의 속성값에 접근 가능render() 의 세번째 인자인 context에 dict 형태로 넘겨진 데이터 중 key 값이 template에서 사용 가능한 변수가 필터, Filters 필터의 기본 형태{{ variable|filter }}변수에 어떠한 작업을 추가적으로 더해 수정하고 싶을때 사용약 60개의 bu..
-
Django MTV 패턴, Templates 작성Django 2024. 8. 12. 10:54
저번에 flask로 가위바위보 게임 웹페이지를 만들어보기도 했지만.. 웹 브라우저에서 열리니까 웹 페이지 맞긴한데.. 근데 왜 네이버나 구글은 진짜 웹 사이트 같은데 내가 만든 건 왜.. 진짜 같지가 않지?🤔 하는 궁금증이 있었다. 그 궁금증에 대한 답은 바로 정적 웹페이지와 동적 웹페이지의 차이였다. 정적 웹페이지(Static Web Page)작성한 상태를 그대로 제공하는 웹 페이지모든 상황에서 동일한 내용을 전달한다.우리가 작성한 HTML을 말한다.동적 웹페이지(Dynamic Web Page)요청에 따라 보여주는 모습이 달라지는(수정되어 보여지는) 웹 페이지예를 들어, A유저가 로그인했을 때와 B유저가 로그인했을 때의 화면이 다름 (받은 메일의 개수, 가입한 카페…)누군가가 수정해줘야 한다는 의..
-
[WIL] 벌써 8월 중순..🫠thoughts💭 2024. 8. 12. 10:53
근래 며칠동안 내가 유리성 같은 곳에 있는 것 같다는 생각이 들었다.가끔은 말도 안되는 일도 하라면 하고, 선 넘는 말도 못 들은 척 하면서 남의 돈 벌어가는 곳이 아닌, 서로 다른 사람들이 모여 우리가 선택한 공부를 하고 어려운 게 있으면 도와달라고 말해도 되는, 사회인듯 사회가 아닌 유리성같은 곳. 저번 조였던 성현님, 율님, 민승님, 정민님과 함께 공부한 시간은 너무 즐거웠다. 모두 같은 스쿼드여서 더 정이 들었던 것 같기도 하고. 팀프로젝트도 같이 했으면 좋았을텐데.. 헤어질 때 너무 아쉬웠다ㅠㅠ 언젠가 다시 만나면 좋겠다. 새롭게 만난 8조 분들과는 아직 낯설지만 모두 좋은 분들 같다. 장고 공부도 팀프로젝트도 사이좋게 잘하고 싶다. 벌써 8월 중순이다. 흘러가는대로 하지말고 끝까지 열심히 ..