我的详细页面没有显示内容(DetailView)

时间:2016-09-05 05:05:40

标签: django django-class-based-views

列表视图有效但当我点击页面中的一个对象时,它只显示我的模板。我究竟做错了什么? 这是我的代码文件。

urls.py

from django.conf.urls import url
from django.views.generic import ListView, DetailView
from imgboard.models import Images
from . import views

urlpatterns = [
    #url(r'^$', views.index, name='index'),
    url(r'^$', ListView.as_view(queryset=Images.objects.all(), template_name="imgboard/home.html")),
    url(r'^(?P<pk>\d+)$', DetailView.as_view(model=Images, template_name="imgboard/girlsdetailed.html")),
    url(r'^contact/$', views.contact, name='contact'),
]

models.py

class Images(models.Model):
    name_person = models.CharField(max_length=70)
    instagram = models.CharField(max_length=200)
    img_url = models.CharField(max_length=500)

    def __unicode__(self):
        return self.name_person

    class Meta:
        verbose_name_plural = 'Images'

views.py

from django.shortcuts import render
from django.http import HttpResponse
from django.views.generic.detail import DetailView
import datetime
from imgboard.models import Images


# assuming its already in templates/ folder:
def index(request):
    return render(request, 'imgboard/home.html')


def current_datetime(request):
    datenow = datetime.datetime.now()
    html = "<html><body>It is now %s.</body></html>" % datenow
    return HttpResponse(html)


def contact (request):
    return render(request, 'imgboard/basic.html', {'content':['If you would   like to contact me, please e-mail me', 'pfftdammitchris@gmail.com']})

home.html的

{% extends "imgboard/header.html" %}

{% block content %}

    {% include "imgboard/includes/listview_code.html" %}

{% endblock %}



listview_code.html
{% block content %}
    {% for xoo in object_list %}
        <p><a href="/imgboard/{{xoo.id}}">{{xoo.name_person}}</a></p>
    {% endfor %}
{% endblock %}

girlsdetailed.html

{% extends "imgboard/header.html" %}

{% block content %}
    <h1>{{ xoo.name_person }}</h1>
    <p>{{xoo.instagram}}</p>
    <p>{{xoo.img_url}}</p>
{% endblock %}

0 个答案:

没有答案