python
-
[Django] Django 연습장 - 7. 이메일 전송 비동기 방식 (celery + redis)프로그래밍/Django 2022. 4. 17. 02:15
지난번 회원 가입 시 이메일 인증하는 프로세스를 추가했습니다. 그렇지만 문제가 있습니다. 이메일을 전송하는 함수는 다소 시간이 소요됩니다. 만약 이메일에 무언가를 첨부한다면 시간은 더욱 늘어납니다. 그러나 django는 Task들을 순서대로 처리합니다. 이 말은 앞에 일이 늦게 끝나면 뒤에 일 들도 처리가 늦어집니다. 이를 방지하기 위해 이메일 전송 및 시간이 오래 걸리는 작업들은 비동기 방식으로 처리합니다. 예를 들어 Event A, Event B 순서로 요청이 들어왔을 때 A->B 순서로 이루어지게 된다. A의 처리가 늦어질수록 B의 처리에 영향이 간다. 그러나 비동기 방식으로 프로세스를 개선한다면 A의 처리완료 여부와 상관없이 B의 작업이 일어난다. 이를 위해서 사용하는 것이 Celery이다. [작..
-
[Django] Django 연습장 - 6. 회원가입 프로세스 개선 (이메일 보내기 & 인증)프로그래밍/Django 2022. 4. 16. 01:48
이번 시간에는 회원가입에 대해서 프로세스를 추가하도록 하겠습니다. 현재 구현해놓은 내용은 이메일을 기반으로 회원가입을 진행합니다. 하지만 지금처럼 가입을 시키면 아무 메일이나, 또는 남의 메일을 입력해서 회원가입을 해버릴 수 있습니다. 따라서 해당 메일이 정말 사용자의 것인지 확인하는 프로세스를 추가하겠습니다. [작업순서] 1. 회원가입 코드에 메일 전송 코드 추가 & 생성 시 user의 is_active값을 False로 저장할 것임, 2. 메일 전송 코드 작성 3. 메일 전송 내용 중 토큰 생성 함수 작성. 4. 메일 전송에 필요한 html 작성 5. 이메일 인증을 위한 엔드포인트 만들기 (user activate) 6. django smtp서버 정보 연결 (Gmail) 7. 회원가입 해보기 1. 회원..
-
[Django] Django 연습장 - 5. html씌우기프로그래밍/Django 2022. 4. 15. 08:00
개인적으로 작업하면 시간도 오래 걸리고 제가 front는 미숙하기 때문에 인터넷에서 free template를 찾아서 가져왔습니다. https://appseed.us/admin-dashboards/django App Generator - Deliver your projects faster | AppSeed Production-ready Admin Dashboards, SSG Starters, JAMstack starters - 24/7 LIVE Suport via Discord. appseed.us 해당 사이트에서 가져왔고 Dashboard에 대한 템플릿을 제공합니다. + 회원가입, 로그인 대시보드를 구현할 것은 아니지만... (나중에 구현할 수도 있고) 로그인 템플릿이 너무 밋밋해서... 템플릿을 씌우..
-
[Django] Django 연습장 - 4. 로그인 기능 만들기프로그래밍/Django 2022. 4. 15. 02:42
이번 시간에는 로그인 기능을 만들어 보겠습니다. 로그인에도 다양한 방식이 있지만 가장 간단하게 django에서 제공하는 login 방식을 사용해보겠습니다. 해당 방식은 session방식으로 jwt방식과는 다릅니다. 차이점은 추후 기회가 되면 설명하겠습니다. [작업 리스트] - 로그인용 페이지 만들기 - 로그인 기능 만들기 app_accounts에서 작업합니다. 1. 로그인용 페이지 만들기. html은 일단 귀찮아서 꾸미지 않는 것으로.. 다음시간에 템플릿을 한 번 찾아보겠습니다. 일단 input받을 수 있는 간단한 html만 만들었습니다. app_accounts > templates > login.html {% csrf_token %} 로그인 이메일 {% if form.email.errors %} {{f..
-
[Django] Django 연습장 - 3. User form 수정해서 회원 가입 조건 변경프로그래밍/Django 2022. 4. 14. 21:20
기존에 만들었던 회원가입은 1. 비밀번호 확인창이 없다. 2. DB에 비밀번호 암호화가 되지 않는다. 두 가지의 문제가 있었습니다. (물론 html css도 안 꾸민 페이지이지만 기능상으로 본 문제점은..) 따라서 form을 변경하여 다음의 문제들을 해결해 보겠습니다. 오늘은 forms.py에 있는 UserForm만 수정하면 됩니다. 1. 비밀번호 확인창 만들기 & 검사하기 기존 코드에서 password_confirm이라는 form 변수를 하나 더 만들고 기존 password도 widget을 추가합니다. -> widget추가 안 하면 input창에 비밀번호 입력하는 게 그대로 보입니다. 그 후 clean 함수를 가져와서 추가하고 싶은 로직을 적습니다. 보시면 아시겠지만 데이터를 가지고 와서 passwor..
-
[Django] Django 연습장 - 2. User만들기프로그래밍/Django 2022. 4. 14. 19:55
대부분의 서비스는 사용자 기반으로 서비스를 진행합니다. 물론 아닌 경우도 있지만 기본적으로 회원 가입 프로세스가 있습니다. 추후에 celery+redis를 사용하여 회원가입 후 인증메일을 비동기로 보내는 것을 테스트할 것이기 때문에 미리 회원가입 기능을 만들어볼까 합니다. [작업 리스트] - app생성 - User모델 만들기 - 회원가입 기능 만들기. 1. 앱 만들기 하나의 기능들을 논리적으로 분리시켜 놓기 위해서 앱이라는 폴더를 생성하게 됩니다. 명령어는 다음과 같습니다. django-admin startapp app_accounts django-admin startapp app_auth 일단 app_accounts에서만 작업할 예정이지만 미리 만들어 놓습니다. 그리고 앱을 만들고 나면 settings..
-
[Django] Django 연습장 - 1.환경세팅프로그래밍/Django 2022. 4. 14. 01:31
Django 여러 가지 개념도 정리하고 자주 사용하는 기능이나 심화 기능도 다시 하면서 연습할 겸 + 잡다한 페이지 만드는 겸 작성하는 글입니다. 이번에는 Django 환경 세팅을 하려고 합니다. [작업 리스트] - django 설치, 프로젝트 세팅 - settings.py 하드코딩 분리 - local db 연결 Django 설치, 프로젝트 세팅 첫 번째로 작업할 프로젝트에 가상 환경을 만들고 django설치 및 프로젝트 설정을 합니다. psycopg2는 제가 사용할 db가 postgresql이라서 설치했습니다. 다른 데이터 베이스 사용 시 사용하지 않으셔도 됩니다. virtualenv venv #... 가상환경 활성화하기하신 후 진행 pip install django django-admin startp..
-
Django & FastAPI 구조 비교, 사용 후기프로그래밍/Python 2022. 1. 19. 00:21
주로 Django를 사용하여 개발을 진행 하다가 시간이 조금 남아서 FastAPI를 사용해보고 있습니다. 같은 Python언어를 사용하지만 Flask도 사용해본 적이 없어서 FastAPI는 많이 낯설더군요... Django 같은 경우는 어느 정도 규격화된 구조가 있지만 FastAPI는 비교적 자유로운 것 같습니다. 위에 올려놓은 그림도 현재 Youtube를 보면서 따라 했을 때 나온 폴더 구조인데 사람마다 다르게 사용할 수 있겠습니다. Django DRF를 사용해서 API를 만들때와 FastAPI를 사용하여 API를 만들 때 대충 위와 같은 구조로 유사한 기능을 한다고 정리를 해봤습니다. FastAPI에서 Common, MiddleWare, DB 폴더를 만들었는데 Common :환경변수 세팅 Middle..