맨 처음 페이지를 바꾸고 싶은데, 어떻게 하면 되나요? (장고)
http://127.0.0.1:8000/ 을 누르면,
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
위와 같이 404화면이 나오고,
http://127.0.0.1:8000/pybo를 해야 질문 리스트가 나옵니다...
혹시, 맨 처음부터 질문 리스트가 나오게 하는 방법이 있나요?
from django.urls import path
from . import views
app_name = 'pybo'
urlpatterns = [
path('', views.index, name='index'),
path('<int:question_id>/', views.detail, name='detail'),
path('answer/create/<int:question_id>/', views.answer_create, name='answer_create'),
]
저의 urls.py이고요,
from django.shortcuts import render , get_object_or_404, redirect
from .models import Question
from django.utils import timezone
def index(request):
"""
pybo 목록 출력
"""
question_list = Question.objects.order_by('-create_date')
context = {'question_list': question_list}
return render(request, 'pybo/question_list.html', context)
def detail(request, question_id):
"""
pybo 내용 출력
"""
question = get_object_or_404(Question, pk=question_id)
context = {'question': question}
return render(request, 'pybo/question_detail.html', context)
def answer_create(request, question_id):
"""
pybo 답변등록
"""
question = get_object_or_404(Question, pk=question_id)
question.answer_set.create(content=request.POST.get('content'), create_date=timezone.now())
return redirect('pybo:detail', question_id=question.id)
views.py 입니다.
책 그대로 따라하고 있고, 현재 2-06까지 진행했습니다!
hello 님 467
2021년 12월 15일 11:36 오후
1개의 답변이 있습니다. 1 / 1 Page
루트 URL을 처리하는 부분은 조금 더 진행하셔야 합니다.
3-05 로그인과 로그아웃 장까지 진행하시면 궁금하신 내용이 해결될 거에요.
박응용 님
M 2021년 12월 16일 8:12 오전