250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- eager
- CHECK OPTION
- 연결리스트
- 데코레이터
- 연관관계
- 다대다
- BOJ
- 일대다
- 낙관적락
- 비관적락
- fetch
- 다대일
- execute
- 스토어드 프로시저
- exclusive lock
- 동적sql
- SQL프로그래밍
- 즉시로딩
- PS
- 스프링 폼
- dfs
- 힙
- 유니크제약조건
- 지연로딩
- JPQL
- 백트래킹
- FetchType
- shared lock
- 이진탐색
- querydsl
Archives
- Today
- Total
흰 스타렉스에서 내가 내리지
게시글 detail 페이지 구현 본문
728x90
urls.py
path('detail/<int:post_id>/', views.detail, name="detail"),
index.html
{% for post in posts %}
<a href="{% url 'detail' post.id %}">
<h3>제목 :
{{ post.title }}
</h3>
</a>
<h4>작성 날짜 :
{{ post.date }}
</h4>
{% endfor %}
pk값을 이용해 특정 모델 객체 하나만 가져오기 : get_object_or_404()
views.py
def detail(request, post_id):
blog_detail = get_object_or_404(Blog, pk=post_id)
return render(request, 'detail.html', {'blog_detail':blog_detail})
detail.html
<h1>제목</h1>
{{ blog_detail.title }}
<h2>날짜</h2>
{{ blog_deatil.date }}
<h3>본문</h3>
{{ blog_detail.body }}
'Django' 카테고리의 다른 글
댓글 (0) | 2022.06.08 |
---|---|
사용자가 media 를 업로드 할 수 있도록 (0) | 2022.06.08 |
DB에 담긴 데이터들을 html에 띄워보자 (0) | 2022.06.07 |
modelForm (0) | 2022.06.07 |
django form 이용하기 (0) | 2022.06.07 |