我正在用本教程創建一個簡單的博客http://lightbird.net/dbe/blog.html。 我是django的新手,我遇到了本教程中的一些步驟問題。 我在盡力去理解,有時候我不明白。我試圖獲取源代碼,但文件已損壞。解釋Django語言
我需要解釋的步驟是:
帖子頁
我們還需要一個單獨的頁面,每個職位與參觀者的意見 和全後的文本(如果我們後來決定限制帖子正文顯示在 的首頁)。以下是我計劃設置的方式:url將爲
/blog/post/{pk}/
其中pk
是帖子對象的主鍵; 模板將被稱爲post.html
和查看功能將post()
。主要上市將展示一個簡單的鏈接:
<div class="commentlink"> <a href="{% url blog.views.post post.pk %}">Comments</a> </div>
我很抱歉,如果這不是一個合適的問題。
我到了後一頁的步驟,我只是不知道該怎麼做!
我views.py
from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.core.urlresolvers import reverse
from django.shortcuts import render_to_response
from blog.models import *
from django.core.context_processors import csrf
from django.http import Http404, HttpResponseRedirect
from django.core.urlresolvers import reverse
def main(request):
"""Main listing."""
posts = Post.objects.all().order_by("-created")
paginator = Paginator(posts, 2)
try: page = int(request.GET.get("page", '1'))
except ValueError: page = 1
try:
posts = paginator.page(page)
except (InvalidPage, EmptyPage):
posts = paginator.page(paginator.num_pages)
return render_to_response("list.html", dict(posts=posts, user=request.user))
def post(request, pk):
"""Single post with comments and a comment form."""
post = Post.objects.get(pk=int(pk))
comments = Comment.objects.filter(post=post)
d = dict(post=post, comments=comments, form=CommentForm(), user=request.user)
d.update(csrf(request))
return render_to_response("post.html", d)
def add_comment(request, pk):
"""Add a new comment."""
p = request.POST
if p.has_key("body") and p["body"]:
author = "Anonymous"
if p["author"]: author = p["author"]
comment = Comment(post=Post.objects.get(pk=pk))
cf = CommentForm(p, instance=comment)
cf.fields["author"].required = False
comment = cf.save(commit=False)
comment.author = author
comment.save()
return HttpResponseRedirect(reverse('blog:add_comment'))
這不是一個步驟,這是一個步驟的*片*。 – 2013-02-16 09:59:36
是的,我做了projectapp,所以雖然我可能會爲lightbird做好準備,但是他們的某些步驟沒有任何意義。沒關係,如果我在30分鐘內向你發送密碼? – supersheep1 2013-02-16 10:05:16
我發給了@cathy – supersheep1 2013-02-16 10:22:43