프로그래밍
-
[Django Project] 게시글 올리기 & 출력하기프로그래밍/Django & Flask 2020. 11. 3. 22:52
과정을 진행하기 전에 유저에게 사진을 입력받고 싶을 땐 media를 등록해야 한다! 게시글 올리기 1. models.py 모델 생성 및 admin 등록 # models.py class imginfo(models.Model): id = models.AutoField(primary_key= True) # 자동 id 부여 nickname = models.CharField(max_length=50) # 사용자 닉네임 like_nums = models.IntegerField(max_length=None) # 좋아요 수 photo = models.ImageField(upload_to="img") # 사진 content = models.CharField(max_length=400) # 글 내용 date = model..
-
[Django] virtualenv Project 시 FileNotFoundError 해결프로그래밍/Django & Flask 2020. 10. 30. 13:59
CMD 창에서 virtualenv Proj를 입력했더니 [Errno 2] No such file or directory: 'C:\\Program Files\\Python37\\lib\\venv\\scripts\\nt\\python_d.exe 다음과 같은 에러가 발생했다. 1) C:\Users\ㅇㅇㅇ\anaconda3 카테고리로 이동 2) 다음과 같은 4개의 파일 복사 3) C:\Users\ㅇㅇㅇ\anaconda3\Lib\venv\scripts\nt 에러가 난 카테고리로 이동해 위의 4개 파일 복사 그 결과 무사히 해결되었다!
-
[Django] TypeError: __init__() missing 1 required positional argument: 'on_delete'프로그래밍/Django & Flask 2020. 10. 26. 21:40
publisher = models.ForeignKey(Publisher) 클래스 안 ForeignKey를 지정하는 과정에서 발생하는 에러인데, 이는 버전의 문제였다 Django 3부터는 ForeignKey를 지정할 때 publisher = models.ForeignKey(Publisher, on_delete=models.CASCADE,) 다음과 같이 on_delete 구문을 넣어줘야 한다.
-
🤖 Django - 클래스형 뷰프로그래밍/Django & Flask 2020. 10. 24. 22:41
클래스형 뷰 뷰는 요청을 받아서 응답을 반환해주는 호출 가능한 객체다. 장고에서는 뷰를 함수로도 작성할 수 있고 클래스로도 작성할 수 있다. 함수형 뷰보다 클래스형 뷰가 장점이 많다. 클래스형 뷰를 사용하면 상속과 미스인 기능을 사용해서 코드를 재사용할 수 있고, 뷰를 체계적으로 구성할 수도 있다. 1) 클래스형 뷰의 시작점 클래스형 뷰를 사용하기 위해서는 URLconf에서 클래스형 뷰를 사용한다고 선언해야 한다. #urls.py from django.conf.urls import patterns from myapp.views import MyView urlpatterns = patterns('', (r'^about/', MyView.as_view()), ) 장고의 URL 해석기는 요청과 관련된 파라미터..
-
🤖 Django - Logging프로그래밍/Django & Flask 2020. 10. 24. 21:24
장고의 로깅 1) 로거 로거는 로깅 시스템의 시작점으로, 로그 메세지를 처리하기 위해 메시지를 담아두는 저장소다. 로거는 로그 레벨을 갖게 되는데, 이는 로그 메시지의 중요도에 따라 자신이 어느 레벨 이상의 메시지를 처리할지에 대한 기준이 된다. * 파이썬 로그 레벨 DEBUG 디버그 용도로 사용되는 정보로, 로그 레벨의 최하위 수준 INFO 일반적이고 보편적인 정보 WARNING 문제점 중에서 덜 중요한 문제점이 발생 시 이에 대한 정보 ERROR 문제점 중에서 주요 문제점이 발생 시 이에 대한 정보 CRITICAL 치명적인 문제점이 발생 시 이에 대한 정보로, 로그 레벨의 최상위 수준 로거에 저장되는 메시지를 로그 레코드라고 하며, 로그 레코드 여시 로그 레벨을 가진다. 로그 레코드는 스택 트레이스 ..