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를 사용하면 생산성이 매우 높아진다.
'기타 > django' 카테고리의 다른 글
작정하고 장고 - login, logout 구현 (0) | 2023.05.09 |
---|---|
작정하고 장고 - CreateView를 통한 회원가입 구현 (0) | 2023.05.08 |
작정하고 장고 - GET, POST (0) | 2023.04.10 |
작정하고 장고 - models.py, db 연동 (0) | 2023.04.07 |
작정하고 장고 - css display 속성, size 단위 (0) | 2023.04.06 |
댓글