728x90
반응형
프젝 작업 전 생각해본 것
- CharField는 max_length가 있어서 인스타그램 2000자 글자수 제한을 만들기는 어렵다. 억지로 구현하면 할 수는 있겠지만 너무 비효율적이고, 실제 인스타그램 구현 로직은 아예 다른 걸 쓴다. 일단 프로젝트에서는 TextField로 구현하기
- 해시태그 30개 제한 max_length랑은 좀 다른 이야기인 거 같고, 일단은 CharField로 데이터를 받아서 views단에서 if문으로 입력받은 개수가 30개가 넘었을 때를 따로 처리해주는 게 나을 거 같다. 튜터님에게도 확인해 보았는데 지금 단계에선 그게 가장 효율적인 방법일 거라고 하셨다.
- VarChar? ORM 모델에서 데이터베이스를 다룰 때 파이썬 문법을 쓰더라도 결국 내부적으로 sql문법으로 전환되어 작동한다. varchar는 CharField와 사실상 동일하고, 변환되는 과정에서 1:1 대응한다. 즉 varchar(바차? 바캐?)는 charfield의 sql 버전같은 것.
마주한 오류
- PostModel이랑 CommentModel을 만드는 과정에서 서로를 ForeignKey로 참조하도록 하니까 윗라인에 적힌 모델에서 그 모델을 참조할 수가 없었다.
- → 해결 : 실제로도 둘 중 하나에는 다른 모델을 외래 키로 참조할 필요가 없었기 때문에 그 부분을 지워줬다.
- 아무리 코멘트를 html에 데이터를 보내도 연결이 안 됐다. 백엔드 코드 상으론 몇 시간을 들여다봐도 아무 문제가 없었다.
- → 해결 : <form>이 중첩되어서 사용되면 안 된다… 바깥 폼태그 지우고 DB연결하고 나서는 삭제도 구현하고 쭉쭉 나갔다.
- db상에서 필드명을 제대로 확인하지 않아 연동이 잘 안 됐었는데, 헷갈릴 때마다 수시로 모델링했던 거 다시 확인하기!
HTTP methods → 참고자료
- request(method, url, args)
- : Sends a request of the specified method to the specified url
- get(url, params, args): args means zero or more of the named arguments in the parameter like requests.delete(url, timeout=2.50)
- : This method returns a requests.Response.object.
- : sends a GET method to the specified url.
- post(url, data, json, args)
- : Sends a POST request to the specified url
- delete(url, args) → 참고자료: args means zero or more of the named arguments in the parameter.
- : This method returns a requests.Response.object.
- : sends a DELETE request to the specified url. DELETE requests are made for deleting the specified resource (file, record etc).
- put(url, data, args)
- : Sends a PUT request to the specified url
- head(url, args): sends a HEAD reqeust to the specified url.: args means zero or more of the named arguments in the parameter like requests.delete(url, timeout=2.50)
- : This method returns a requests.Response.object.
- : HEAD requests are done when you don’t need the content of the file, but only the status_code or HTTP headers.
- : This makes a HEAD request to a web page, and returns the HTTP headers.
- patch(url, data, args)
- : Sends a PATCH request to the specified url
반응형
'Programming > TIL and WIL' 카테고리의 다른 글
| 221009 Today I Learned (TIL) (0) | 2022.10.09 |
|---|---|
| 221006 TIL - 프로젝트 피드백 및 팀 회고 (2) | 2022.10.07 |
| 221004 Today I Learned (TIL) (0) | 2022.10.07 |
| 221003 Today I Learned (TIL) (0) | 2022.10.04 |
| 220929 Today I Learned (TIL) (0) | 2022.09.30 |