반응형
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 | 29 | 30 | 31 |
Tags
- Optimization
- daspecialty
- 장고
- 리트코드
- elasticsearch
- Medium
- Spark
- CentOS
- 엘라스틱서치
- RecommendationSystem
- 해시
- dump
- 알고리즘
- Easy
- 깊이우선탐색
- twosum
- AWS
- python
- 키바나
- ELK
- 스파크
- programmers
- leetcode
- 파이썬
- solution
- Algorithm
- kibana
- Django
- 프로그래머스
- dfs
Archives
- Today
- Total
Archive
[Django] Project Home Page (실습4) 본문
반응형
*실습1/실습2/실습3/ 에 이어지는 내용으로, 클래스 뷰 활용
1. 패이지 설계
루트 페이지 생성
1) UI 설계
2) View Flow 설계
2. URLconf
설계한 View Flow를 참고하여 URLconf를 정의
#Djangoproject/urls.py
from django.contrib import admin
from django.urls import path, include
#import view
from djangoProject import views
urlpatterns = [
path('admin/', admin.site.urls),
#루트 페이지 추가
path('', views.HomeView.as_view(), name='home'),
path('polls/', include('polls.urls')),
path('books/', include('books.urls'))
]
3. View
#DjangoProject/views.py
from django.views.generic.base import TemplateView
class HomeView(TemplateView):
template_name = 'home.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['app_list'] = ['polls','books']
return context
4. Template
{% extends "base.html" %}
{% block content %}
<h2>Django Application</h2>
<ul>
{% for appname in app_list %}
{% with appname|add:":"|add:"index" as urlvar %}
<li><a href="{% url urlvar %}">{{ appname }}</a></li>
{% endwith %}
{% endfor %}
</ul>
{% endblock content %}
5. Run Server
$ python manage.py runserver
반응형
'------ Web ------ > Backend' 카테고리의 다른 글
[Django] Book Application 개발 (실습3) (0) | 2022.07.13 |
---|---|
[Django] Class-based View (0) | 2022.07.04 |
[Django] Form (0) | 2022.07.03 |
[Django] Template System (0) | 2022.06.28 |
[Django] Admin (0) | 2022.06.26 |
Comments