“Practical django Projects”,第2版,源代码 [英] "Practical django Projects, 2nd ed., source code

查看:143
本文介绍了“Practical django Projects”,第2版,源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在詹姆斯·班内特的实用django项目(第2版)中,作者构建了一个内容管理系统,利用了django.contrib.admin。问题是它不起作用。



我在第三章中添加了关键字搜索功能,添加了一个新的管理模块。问题是我不能让它上班。浏览网页时,我发现不断的投诉,尽管书中声称,作者没有提供工作来源。问题的核心在于,他似乎依赖于每个次要版本都在改变的django平台的内部结构,因此他的解决方案证明是脆弱的。



仍然,我'我喜欢这样做。



在第三章中,他应该添加一个新的搜索关键字admin函数,通过创建一个新的SearchKeyword模型,然后创建和注册一个SearchKeywordAdmin类。



模型(在cms / search / models.py:

  class SearchKeyword(models.Model):
keyword = models.CharField(max_length = 50)
page = models.ForeignKey(FlatPage)

def __unicode__ (self):
return self.keyword

该类(在cms / search / admin .py):

  class SearchKeywordAdmin(admin.ModelAdmin):
pass

admin .site.register(SearchKeyword,SearchKeywordAdmin)

我看不到编译错误,但是在管理页面上看不到任何内容。



我做错了,或者django.contrib.admin中的某些内容发生了变化,使得该代码不再工作。 / p>

任何人都有什么想法?我可能需要做什么来使这项工作?

解决方案

你的代码对我来说健康,所以你没有张贴是错误的。



您是否导入所需的一切?




  • 您的 models.py 需要 django.db.models FlatPage (可能是从 django.contrib.flatpages.FlatPage

  • 您的 admin.py 需要从django.contrib导入admin 从cms.search.models导入SearchKeyword



cms.search / dev / ref / settings /?from = olddocs#installed-appsrel =nofollow noreferrer> INSTALLED_APPS 设置?


In James Bennett's "Practical django Projects" (2nd edition) the author builds a content management system, leveraging off of django.contrib.admin. The problem is that it doesn't work.

I'm in chapter three, where he adds a keyword search capability, by adding a new admin module. The problem is is that I can't get it to work. Browsing around the web, I find constant complaints that despite the claims in the book, the author has not made working source available. The core of the problem is that he seems to be depending upon internals of the django platform that are changing with every minor release, hence his solutions prove fragile.

Still, I'd like to work my way through this.

In chapter three, he supposedly adds a new search keyword admin function, by creating a new SearchKeyword model, and then creating and registering a SearchKeywordAdmin class.

The model (in cms/search/models.py:

class SearchKeyword(models.Model):
    keyword = models.CharField(max_length=50)
    page = models.ForeignKey(FlatPage)

    def __unicode__(self):
        return self.keyword

The class (in cms/search/admin.py):

class SearchKeywordAdmin(admin.ModelAdmin):
    pass

admin.site.register(SearchKeyword, SearchKeywordAdmin)

I see no compile errors, but I see nothing on the admin page.

Either I'm doing something wrong, or something in django.contrib.admin has changed, to make this code no longer work.

Anyone have any ideas which? And what I might need to do to make this work?

解决方案

Your code looks healthy to me, so something you've not posted is wrong.

Are you importing everything required?

  • Your models.py needs django.db.models and FlatPage (presumably from django.contrib.flatpages.FlatPage)
  • Your admin.py needs from django.contrib import admin and from cms.search.models import SearchKeyword

Is cms.search in your INSTALLED_APPS setting?

这篇关于“Practical django Projects”,第2版,源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆