점프투 장고 2-03 조회와 탬플릿 질문입니다.
url.py 을
from django.urls import path
from . import views
urlpatterns = [
path('', views.index),
path('<int:question_id>/', views.detail),
]
요렇게 고치고
views.py 를
from django.shortcuts import render
# Create your views here.
from django.http import HttpResponse
from .models import Question
# def index(request):
# return HttpResponse("안녕하세요 pybo에 오신것을 환영합니다.")
def detail(request, question_id):
"""
pybo 내용 출력
"""
question = Question.objects.get(id=question_id)
context = {'question': question}
return render(request, 'pybo/question_detail.html', context)
이렇게 고치고
qustion_detail.html 을만들어
<h1>{{ question.subject }}</h1>
<div>
{{ question.content }}
</div>
이렇게 하고
서버를 재시작 하니
(mysite) C:\projects\mysite>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\python\lib\threading.py", line 973, in _bootstrap_inner
self.run()
File "C:\python\lib\threading.py", line 910, in run
self._target(*self._args, **self._kwargs)
File "C:\venvs\mysite\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\venvs\mysite\lib\site-packages\django\core\management\commands\runserver.py", line 118, in inner_run
self.check(display_num_errors=True)
File "C:\venvs\mysite\lib\site-packages\django\core\management\base.py", line 392, in check
all_issues = checks.run_checks(
File "C:\venvs\mysite\lib\site-packages\django\core\checks\registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\venvs\mysite\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\venvs\mysite\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\venvs\mysite\lib\site-packages\django\urls\resolvers.py", line 408, in check
for pattern in self.url_patterns:
File "C:\venvs\mysite\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\venvs\mysite\lib\site-packages\django\urls\resolvers.py", line 589, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\venvs\mysite\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\venvs\mysite\lib\site-packages\django\urls\resolvers.py", line 582, in urlconf_module
return import_module(self.urlconf_name)
File "C:\python\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:\projects\mysite\config\urls.py", line 22, in <module>
path('pybo/', include('pybo.urls')),
File "C:\venvs\mysite\lib\site-packages\django\urls\conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "C:\python\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:\projects\mysite\pybo\urls.py", line 6, in <module>
path('', views.index),
AttributeError: module 'pybo.views' has no attribute 'index'
이렇게 나오네요 ㅜㅜ
뭐가 잘못된것 일까요?
psymaru7 님 694
M 2021년 11월 28일 12:42 오후
index 함수 주석처리를 해제하세요.
-
박응용님,
2021년 11월 28일 3:09 오후
추천
,
대댓글