我正在關注一些基本的django博客教程。我堅持的部分是如何在我的網址中設置變量。如何設置我的網址與帖子/ 1,帖子/ 2等?
我想我的網址看起來像:
posts/1
posts/2
posts/3
目前,當我訪問我的index.html我看到博客文章(只是標題)的列表,當我將光標懸停在各個環節它不顯示帖子/ 1,帖子/ 2等
問題是,當我點擊這些鏈接時,它基本上只是刷新頁面,並沒有顯示詳細的視圖。
我urls.py目前看起來是這樣的:
url(r'^posts/', index),
url(r'^posts/(?P<post_id>[0-9]+)/$', detailedview),
我不知道到底是什麼/ $」,不和我假設是這樣的(P [0-9] +?)問題,因爲detailview永遠不會被調用。
這個方法在我的views.py裏面,但是再次,它永遠不會被調用。
def detailedview(request, post_id):
targetpost = Post.objects.get(id="post_id")
context = {'targetpost': targetpost}
return render(request, 'posts/detailedview.html', context)
你真的需要通過[教程](https://docs.djangoproject.com/en/1.8/intro/tutorial03/)。 –
我是。本練習直接從教程中獲取。 – stephan