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 ?
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 .
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 !