Skip to main content

Command Palette

Search for a command to run...

urls.py오류

Published
1 min readView as Markdown
P

저는 사람입니다 아마도요

사용이유
urlpatterns = router.urls

않이 편해짐 자동으로 처리해줌
urls.py 안됐던이유

TypeError: 'module' object is not iterable ImproperlyConfigured: The included URLconf 'note.urls' … does not appear to have any patterns

원인

  • note/urls.pyurlpatterns 변수가 없거나, 리스트 형식이 아니었음.

  • urlpatterns 이름을 잘못 쓰거나(urlpattenrs 등), include()를 잘못 사용.
    해결

  • note/urls.py
    python복사편집urlpatterns = [
    path('diary/', note_list),
    path('diary/edit/<int:pk>/', note_detail), ]

    같이 반드시 리스트로 정의.

  • 프로젝트 루트 diary/urls.pypath('api/', include('note.urls')) 추가.

오류
ImportError: cannot import name 'NoteViewSet' from 'note.views'

원인

  • note/views.py가 기본으로 생성된 “빈 파일” 상태였음.
    해결

  • views.py에 아래 클래스를 추가:

    • from rest_framework import viewsets
      from .models import Note
      from .serializers import NoteSerializer

      class NoteViewSet(viewsets.ModelViewSet):
      queryset = Note.objects.all()
      serializer_class = NoteSerializer

urls
처음부터
path('api/', include('note.urls')), 이거 때문에 안됐음
해결 방법 주석 처리하고 migrate하고 migration 하고 주석 풀면 쉽게 됐음