最近看到django通用视图部分(
http://djangobook.py3k.cn/2.0/chapter11/),做到这一步;说明我的project名--generic,book-app是generic/generic/book
#
model.py,之前例子中Publisher的定义(generic/generic/book/
model.py)
class Publisher(models.Model):
name = models.CharField(max_length=30)
address = models.CharField(max_length=50)
city = models.CharField(max_length=60)
state_province = models.CharField(max_length=30)
country = models.CharField(max_length=50)
website = models.URLField()
def __unicode__(self):
return
self.name#
urls.py 在generic/generic/
urls.pyfrom django.conf.urls.defaults import *
from django.views.generic import list_detail
from mysite.books.models import Publisher
publisher_info = {
'queryset': Publisher.objects.all(),
'template_name': 'publisher_list_page.html',
}
urlpatterns = patterns('',
url(r'^publishers/$', list_detail.object_list, publisher_info),
)
模板在generic/templates下,generic/templatespublisher_list_page.html
publisher_list_page.html
<h2>Publishers</h2>
<ul>
{% for publisher in object_list %}
<li>{{
publisher.name }}</li>
{% endfor %}
</ul>
浏览器请求ocalhost:8000/publishers,但是页面一直显示:
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/publishers
Using the URLconf defined in generic.urls, Django tried these URL patterns, in this order:
1.^about/$
2.^publishers/$
The current URL, publishers, didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
https://www.v2ex.com/t/48870
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.