ModuleNotFoundError: No module named 'apps.accounts.urls'

라는 에러가 뜨는 경우

settings.py 에 해당 app을 작성해줬는지 먼저 확인하자

작성해주었으면

django.core.exceptions.ImproperlyConfigured:

Cannot import 'accounts'. Check that 'apps.accounts.apps.AccountsConfig.name' is correct.

이런 에러가 또 나올 가능성이 있는데

apps.accounts.app.py 의 name 을 확인해줬는데 맞게 입력됐는데..?

이렇게 고쳐주면 해결된다. (디렉토리 구조 때문에 생긴 에러였음)


참고

참고 자료

127.0.0.1:8000/admin/ 페이지가 안뜬다 왜 그럴까..

 

https://www.youtube.com/watch?v=Gr8CVnRUoDo&ab_channel=ProblemSolvingPoint 

 

이렇게 했는데도 안된다..

https://jamanbbo.tistory.com/19

 

You are trying to add a non-nullable field '필드명' to post without a default 해결

django 에서 models.py를 수정하고 migration을 하려고 하면 You are trying to add a non-nullable field '필드명' to post without a default; we can't do that (the database needs something to populate exi..

jamanbbo.tistory.com

 

/api/posts/5/ 에서 title, content, thumbnail 을 PUT 요청으로 update 해볼 것임.

 

postman 으로 PUT 요청을 보내면 위와 같은 에러가 뜬다.

 

AssertionError: The `.update()` method does not support writable dotted-source fields by default.
Write an explicit `.update()` method for serializer `apps.post.serializers.PostWriteSerializer`, or set `read_only=True` on dotted-source serializer fields.

읽기 전용 필드에서는 update() 메서드를 쓸 수 없다는 말 같다.

이거 때문에 create() 도 안됬었는데 해결 방법을 찾아보자.

AttributeError: Got AttributeError when attempting to get a value for field `thumbnail_path` on serializer `PostWirteSerializer`.
The serializer field might be named incorrectly and not match any attribute or key on the `Post` instance.
Original exception text was: 'Post' object has no attribute 'thumbnail_path'.

PostDetail 뷰로 보려고 했는데 위와 같은 에러가 떳다

 

Post 모델에서 thumbnail_path 컬럼을 확인해보면

thumbnail_path = serializers.CharField() 라고 되어있었는데

 

thumbnaill = serializers.ImageField(source="thumbnail.source" 로 고쳤더니

 

/api/posts/1/

Post Detail 뷰가 잘 작동하는 것을 알 수 있다.

 

여기서 알게 된건

/api/posts/1 -> 동작o

/api/posts/1/ -> 동작o

 

/api/posts/2 -> 동작x

/api/posts/2/ -> 동작o

 

<int:1> 의 경우 끝에 /(슬래시)를 안붙여줘도 동작하는데

<int:2> 부터는 무조건 끝에 /(슬래시)가 있어야 동작한다.

 

delete 요청도 잘 동작한다.

https://buildabetterworld.tistory.com/75

 

https://gmlwjd9405.github.io/2018/05/25/git-add-cancle.html

 

 

로그인을 해야 email 필드가 채워지는데 shell 창에서 로그인을 어떻게 하는지 모르겠어서 찾아봤음...

 

 

Client 클래스를 상속 받고

 

위 처럼 shell 창에 작성해줄 것임

def 뭐시기를 이용하는건 아니므로 self 를 빼고 작성해줄 것임.

 

이런식으로 작성해주고 다시 해봤는데

(이건 테스트 코드로 테스트 해볼때 이렇게 하는듯)

 

이렇게 해보자

 

author_id 를 어떻게 가져와야 되는지 모르겠음

 

Postman 으로 위와 같이 요청보냈는데 또 에러 발생

 

The `.create()` method does not support writable dotted-source fields by default.
Write an explicit `.create()` method for serializer `apps.post.serializers.PostSerializer`, or set `read_only=True` on dotted-source serializer fields.

 

사실 postman 상에서 로그인이 되는지 먼저 구현시키고

그다음 author, title, content, thumbnail 을 채워서 요청시켜야 되는데

지금은 로그인을 먼저 구현시키지 않은상태에서 요청을 보냈음

그래서 다시 터미널창에서 시도해볼 것임

 

Post 모델의 컬럼에 뭐 있는지 확인해봄

post 컬럼에 뭐가 있는지 확인해봤는데

ForeignKey로 연결한 author 의 author_id 가 있고

OneToOne로 연결한 thumbnail 의 thumbnail_id 가 생겨있는 상태더라

 

User 모델의 컬럼에 뭐 있는지 확인해봄
이렇게 해서 저장하려 했는데..

 

FOREIGN KEY 를 못가져오고 있다. 왜그럴까
author_id 는 admin@naver.com 이였음. autoincrement 처럼 번호가 붙여지는줄 착각함.

 

author 에 맞는 이메일을 기입하였는데 자꾸 유효한 이메일 주소를 입력하란다.


참고

https://cw9206.tistory.com/105

 

[IntegrityError, Not NULL constraint failed]

'IntegrityError, Not NULL constraint failed' 문제 해결하기 에러 발생 상황 로그인 후, User 별로 글 작성 기능을 넣기 위해 post_new 메서드를 구현한 상태 user 모델을 Post 모델의 Foreign Key로 설정해놓..

cw9206.tistory.com

https://blog.myungseokang.dev/posts/newbie-tests-view-in-django/

 

테스트 초보의 테스트 삽질기 with Django

Newbie's test shovel with Django

blog.myungseokang.dev

https://kimdoky.github.io/django/2018/05/01/django-shell-auth/

 

Django - shell에서 login하기

on May 1, 2018 under django 1 minute read 장고에서 작업 진행 내용을 확인하려면 로그인을 해야하는 경우들이 필수적으로 발생한다. >>> from django.contrib.auth import authenticate >>> user = authenticate(username='id', pass

kimdoky.github.io

https://nachwon.github.io/django-9-ORM/

 

[Django Tutorial] Blog 만들기 - 9. ORM

동적으로 템플릿을 생성하기 위해서는 먼저 ORM 에 대해 알아야한다.

nachwon.github.io

https://buildabetterworld.tistory.com/75

 

[Django-Rest-Framwork] Postman에서 csrftoken 자동화하기

< Postman에서 csrftoken 자동화하기 > 빈둥거리며 살다가 이제야 정신을 차리고, 다시 하던것들을 조금씩 정리하고 기록으로 남기기로 했다. 학교에서 진행하는 해커톤을 준비하면서 Django-Rest-Framwo

buildabetterworld.tistory.com

 

+ Recent posts