Q&A

책을 따라하다가 막히는 부분이 있나요?
질문을 남겨주세요.

models.py 설치 후 재설치

2 years, 8 months ago

id746011 id746011

C:\github\website-practice\mysite(main -> origin)

(venv) λ python manage.py test

Found 1 test(s).

Creating test database for alias 'default'...

Destroying test database for alias 'default'...

Traceback (most recent call last):

  File "C:\github\website-practice\mysite\manage.py", line 22, in <module>

    main()

  File "C:\github\website-practice\mysite\manage.py", line 18, in main

    execute_from_command_line(sys.argv)

  File "C:\github\website-practice\venv\lib\site-packages\django\core\management\__init__.py", line 446, in execute_from_command_line

    utility.execute()

  File "C:\github\website-practice\venv\lib\site-packages\django\core\management\__init__.py", line 440, in execute

    self.fetch_command(subcommand).run_from_argv(self.argv)

  File "C:\github\website-practice\venv\lib\site-packages\django\core\management\commands\test.py", line 24, in run_from_argv

    super().run_from_argv(argv)

  File "C:\github\website-practice\venv\lib\site-packages\django\core\management\base.py", line 414, in run_from_argv

    self.execute(*args, **cmd_options)

  File "C:\github\website-practice\venv\lib\site-packages\django\core\management\base.py", line 460, in execute

    output = self.handle(*args, **options)

  File "C:\github\website-practice\venv\lib\site-packages\django\core\management\commands\test.py", line 68, in handle

    failures = test_runner.run_tests(test_labels)

  File "C:\github\website-practice\venv\lib\site-packages\django\test\runner.py", line 1006, in run_tests

    self.run_checks(databases)

  File "C:\github\website-practice\venv\lib\site-packages\django\test\runner.py", line 925, in run_checks

    call_command("check", verbosity=self.verbosity, databases=databases)

  File "C:\github\website-practice\venv\lib\site-packages\django\core\management\__init__.py", line 198, in call_command

    return command.execute(*args, **defaults)

  File "C:\github\website-practice\venv\lib\site-packages\django\core\management\base.py", line 460, in execute

    output = self.handle(*args, **options)

  File "C:\github\website-practice\venv\lib\site-packages\django\core\management\commands\check.py", line 76, in handle

    self.check(

  File "C:\github\website-practice\venv\lib\site-packages\django\core\management\base.py", line 487, in check

    all_issues = checks.run_checks(

  File "C:\github\website-practice\venv\lib\site-packages\django\core\checks\registry.py", line 88, in run_checks

    new_errors = check(app_configs=app_configs, databases=databases)

  File "C:\github\website-practice\venv\lib\site-packages\django\core\checks\urls.py", line 14, in check_url_config

    return check_resolver(resolver)

  File "C:\github\website-practice\venv\lib\site-packages\django\core\checks\urls.py", line 24, in check_resolver

    return check_method()

  File "C:\github\website-practice\venv\lib\site-packages\django\urls\resolvers.py", line 480, in check

    for pattern in self.url_patterns:

  File "C:\github\website-practice\venv\lib\site-packages\django\utils\functional.py", line 49, in __get__

    res = instance.__dict__[self.name] = self.func(instance)

  File "C:\github\website-practice\venv\lib\site-packages\django\urls\resolvers.py", line 696, in url_patterns

    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)

  File "C:\github\website-practice\venv\lib\site-packages\django\utils\functional.py", line 49, in __get__

    res = instance.__dict__[self.name] = self.func(instance)

  File "C:\github\website-practice\venv\lib\site-packages\django\urls\resolvers.py", line 689, in urlconf_module

    return import_module(self.urlconf_name)

  File "C:\Users\LG\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module

    return _bootstrap._gcd_import(name[level:], package, level)

  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import

  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load

  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked

  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked

  File "<frozen importlib._bootstrap_external>", line 850, in exec_module

  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed

  File "C:\github\website-practice\mysite\mysite\urls.py", line 10, in <module>

    path('', include('single_pages.urls')),

  File "C:\github\website-practice\venv\lib\site-packages\django\urls\conf.py", line 38, in include

    urlconf_module = import_module(urlconf_module)

  File "C:\Users\LG\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module

    return _bootstrap._gcd_import(name[level:], package, level)

  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import

  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load

  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked

  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked

  File "<frozen importlib._bootstrap_external>", line 850, in exec_module

  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed

  File "C:\github\website-practice\mysite\single_pages\urls.py", line 2, in <module>

    from . import views

  File "C:\github\website-practice\mysite\single_pages\views.py", line 3, in <module>

    from models import Post

ModuleNotFoundError: No module named 'models'

models.py

from django.db import models

views.py

from django.shortcuts import render
from django.views.generic import ListView, DetailView
from models import Post


class PostList(ListView):
model = Post
ordering = '-pk'


class PostDetail(DetailView):
model = Post

# def index(request):
# posts = Post.objects.all().order_by('-pk')
#
# return render(
# request,
# 'blog/index.html',
# {
# 'posts': posts,
# }
# )


# def single_post_page(request, pk):
# post = Post.objects.get(pk=pk)
#
# return render(
# request,
# 'blog/single_post_page.html',
# {
# 'post': post,
# }
# )
뭐가 문제일까요..? 파이참 삭제 후 재설치 해야할까요..?

sungyong
sungyong   2 years, 8 months ago

안녕하세요. 

models 앞에 점이 하나 빠졌네요. 

from models import Post

가 아니라

from .models import Post

로 수정해주세요. 


Updated: March 28, 2022, 10:54 p.m.

Leave a Comment:
목록보기
Search
  • 자유게시판
  • Q&A