본문 바로가기
기타/django

작정하고 장고 - for 루프, 디버깅

by 방배킹 2023. 4. 11.

18강 - DB 정보 접근 및 장고 템플릿 내 for loop

views.py

def hello_world(request):

    if request.method == "POST":
        temp = request.POST.get('hello_world_input')
        new_hello_world = helloWorld()
        new_hello_world.text = temp
        new_hello_world.save()
        return HttpResponseRedirect(reverse('accountapp:hello_world'))

    else:
        hello_world_list = helloWorld.objects.all()
        return render(request, 'accountapp/hello_world.html', context={'hello_world_list': hello_world_list})

views.py를 다음과 같이 설정해준뒤 html 문서의 for 루프를 작성해주자.

for 루프

{% if hello_world_list %}
    {% for hello_world in hello_world_list %}
    <h4>
        {{ hello_world.text }}
    </h4>
    {% endfor %}
{% endif %}

같은 방법으로 for문을 작성해준다.

실습

19강 - Pycharm 디버깅 설정


Edit configurations 클릭


source 파일 선택


파라미터에 runserver 작성


manage 파일 우클릭 이후 Debug manage 클릭


debug를 할때도 서버가 실행이된다.


이때 break point 설정


debug 단어 post 전송


다음과 같이 중단점에서 멈추어서 현재 상태를 알 수 있다.

오류 발생시


manage파일이 자동으로 생기는데 해당 파일의 파라미터에도 runserver를 추가해준다.

20강 - Class Based View, 장고의 CRUD

CRUD

Create, Read, Update, Delete

CBV vs FBV

class based view, function based view
CBV를 사용하면 생산성이 매우 높아진다.

댓글