程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Django personal blog building --5-- click the list to display the specific content

編輯:Python

Preface :

        • The next step is to write registration and login !

There is another point that was not mentioned in the last article , Is that I am in every div It's all wrapped in q label , That one a What does the label mean ?

One html Show different details

        • The next step is to write registration and login !

We can create a detail Of html file , Corresponding , Need to be in app Of urls.py Add routes there , And in views.py Write view functions .
For the sake of later app There will be no confusion when there are more , We can do it in templates Create a new folder under folder , My name is blogmuban, Create... In this folder xiangqing.html

stay urls.py Next add a statement :

url(r'^detail/$',views.detail),

At this time, go to views.py

def detail(request):
nid = request.GET.get('nid')
articleList = Article.objects.all()
ar = articleList.values('img')
for i in ar:
articleList.img = i['img']
detail_info = articleList[int(nid)-1]
return render(request, 'blogmuban/xiangqing.html', {
'detail_info':detail_info})

You can ignore the first sentence of the code :nid = request.GET.get('nid')
Now go to the home page html

<a href="/detail/?nid={
{ article.pk }}">
</a>

here pk It's backstage id It means . We put id Assign a value to nid, Represents which list we click , then url In the process of value transfer , hold nid be equal to id The value of is passed to the view function , There is that sentence nid = request.GET.get('nid')
At this time, we take out the data like the home page Article All data in the table is assigned to articleList, because articleList It's a list , The traversal of the list starts from 0 Start , And what we got nid Nor is it a number , It's a string , So we need First cast to int Form minus one , Then assign this new dictionary to detail_info, Then send the value to the details page xiangqing.html
Finally, according to your own html Style to display .

  • Later I thought of a simpler method :
    Get it from nid Where? , utilize filter() Method
detail_info = Player.Object.filter(id=nid)

And then use for The sentence put img Take out the specific path , Then you can transfer values !

  • filter() The way is to put id=nid Take out the value of , because id Is the only one. , So there will certainly be no case of taking out multiple values !

The next step is to write registration and login !


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved