【发布时间】:2012-01-26 21:22:14
【问题描述】:
我正在尝试为论坛主题创建回复页面。论坛视图和线程视图工作正常,但我在设置回复和启动新线程页面时遇到问题。已成功创建话题和论坛。
这是我的views.py:
def post(request, ptype, pk):
"""Display a post form."""
action = reverse("webnotes.forum.views.%s" % ptype, args=[pk])
if ptype == "new_thread":
title = "Start New Topic"
subject = ''
elif ptype == "reply":
title = "Reply"
subject = "Re: " + Thread.objects.get(pk=pk).title
return render_to_response("forum/post.html",add_csrf(request,subject=subject,action=action, title=title))
def new_thread(request, pk):
"""Start a new thread."""
p = request.POST
if p["subject"] and p["body"]:
forum = Forum.objects.get(pk=pk)
thread = Thread.objects.create(forum=forum,title=p["subject"],creator=request.user)
Post.objects.create(thread=thread, title=p["subject"],body=p["body"],creator=request.user)
return HttpResponseRedirect(reverse("webnotes.forum.views.forum", args=[pk]))
def reply(request, pk):
"""Reply to a thread."""
p = request.POST
if p["body"]:
thread = Thread.objects.get(pk=pk)
post = Post.objects.create(thread=thread,title=p["subject"],body=p["body"],creator=request.user)
return HttpResponseRedirect(reverse("webnotes.forum.views.thread", args=[pk])+"?page=last")
这是我的 urls.py:
url(r"^post/(new_thread|reply)/(\d+)/$", "forum.views.post"),
url(r"^post/reply/(\d+)/$", "forum.views.reply"),
url(r"^post/new_thread/(\d+)/$", "forum.views.new_thread"),
当我转到http://localhost:8000/post/reply/1/ 时,我得到:
未找到带有参数“(u'1',)”和关键字参数“{}”的“webnotes.forum.views.reply”的反向操作。
我还发现这是在回溯中:
action = reverse("webnotes.forum.views.%s" % ptype, args=[pk])
对应于views.py。有什么问题?我希望我已经说清楚了。如果需要任何其他信息,我很乐意提供。
附:我正在关注这个网站上的教程:http://www.lightbird.net/dbe/forum1.html
【问题讨论】:
标签: django view django-urls