Skip to content

Commit

Permalink
FBV를 CBV로 바꿈
Browse files Browse the repository at this point in the history
  • Loading branch information
정경업 committed Feb 4, 2015
1 parent 148b4de commit 22595aa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion blog/templates/base.html
Expand Up @@ -8,7 +8,7 @@
<title>파이로그</title>
</head>
<body>
<h1>파이로그</h1>
<h1><a href="{% url 'home' %}">파이로그</a></h1>
{% block content %}
{% endblock %}
</body>
Expand Down
15 changes: 6 additions & 9 deletions blog/views.py
@@ -1,17 +1,14 @@
# -*- coding: utf-8 -*-
from django.shortcuts import render, get_object_or_404
from django.views.generic import ListView, DetailView

from blog.models import Post


def home(request):
class PostList(ListView):
model = Post
template_name = 'home.html'
posts = Post.objects.all()
context_data = {'object_list': posts}
return render(request, template_name, context_data)


def detail(request, pk):
class PostDetail(DetailView):
model = Post
template_name = 'detail.html'
post = get_object_or_404(Post, id=pk)
context_data = {'object': post}
return render(request, template_name, context_data)
5 changes: 3 additions & 2 deletions pylog/urls.py
@@ -1,10 +1,11 @@
from django.conf.urls import patterns, include, url
from django.contrib import admin
from blog.views import PostList, PostDetail

urlpatterns = patterns('',
# Examples:
url(r'^$', 'blog.views.home', name='home'),
url(r'^(?P<pk>\d+)/$', 'blog.views.detail', name='detail'),
url(r'^$', PostList.as_view(), name='home'),
url(r'^(?P<pk>\d+)/$', PostDetail.as_view(), name='detail'),
# url(r'^blog/', include('blog.urls')),

url(r'^admin/', include(admin.site.urls)),
Expand Down

0 comments on commit 22595aa

Please sign in to comment.