Q&A

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

p.275쪽 문제 해결 도와주세요

2 years, 7 months ago

id746011 id746011

안녕하세요.. 문제가 생겼는데 도저히 모르겠습니다..

Creating test database for alias 'default'...

System check identified no issues (0 silenced).

E

======================================================================

ERROR: test_post_detail (blog.tests.TestView)

----------------------------------------------------------------------

Traceback (most recent call last):

File "C:\github\website-practice\mysite\blog\tests.py", line 27, in test_post_detail

self.assertIn('Blog', navbar.text)

AttributeError: 'NoneType' object has no attribute 'text'

----------------------------------------------------------------------

Ran 1 test in 0.040s

FAILED (errors=1)

Destroying test database for alias 'default'...

어제 이런식으로 떠가지고.. models.py 그 부분이 잘못된건가?라는 생각으로 models.py 삭제하고 다시 만들었

는데 이런 문제가 생겼습니다..


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

ImportError: cannot import name 'Post' from 'single_pages.models' (C:\github\website-practice\mysite\single_pages\models.py)


책에 나와 있는대로 한 것 같은데 혹시 제가 잘못한게 있으면 알려주실 수 있나요..?


sungyong
sungyong   2 years, 7 months ago

음. 이 메시지를 잘 봐야 할 것 같은데요. 

AttributeError: 'NoneType' object has no attribute 'text'

navbar.text 에서 navbar가 None으로 되어 있고, 따라서 text가 없다는 의미입니다. navbar로 지정한 항목을 html에서 찾을 수 없었나봅니다. 

따라서 해당 항목이 잘 정의되어 있는지 확인이 필요합니다. 


더 자세한 답변을 원하신다면, 해당 html 파일과 views.py, tests.py를 보여주셔야 할 것 같아요. 

Updated: March 28, 2022, 11:26 p.m.

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