在做到編輯部分時,想到的辦法是在編輯上跳轉到頁面時給他一個包含唯一標識id的url,然后通過這個url中的id去查詢出該條數據,將數據內容顯示在編輯頁面。
1.編輯按鈕
<button onclick="window.location='/edit/{{ project.id }}'"><a href="/edit/">編輯</a></button>
2.URL配置,用()括起來的部分就是參數,如果有多個參數,使用多個()
urlpatterns = patterns('',
……
('^edit/(\w+)',views.edit),
) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
3.view.py中的編輯方法,每個方法第一個參數都要是默認的request,第二個參數,第三個參數等就可以是從url中獲取到的參數
def edit(request,param):
post = project.objects(id=param)[0]
……
return render_to_response("edit.html", locals(),context_instance=RequestContext(request))