- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以,我通过这个学习 django http://mherman.org/blog/2012/12/30/django-basics/教程,我有一个问题。
我在数据库中添加了几本书,但在管理站点中我只看到“App_name 对象”。在我的例子中,我只看到单词列表“Books object”、“Books object”、“Books object”,而实际上我应该看到“War and Peace”、“Brave New World”、“To Kill a Mockingbird”。
那么,你知道我的应用有什么问题吗?
谢谢;)
已编辑:添加我的 models.py 代码
from django.db import models
class Books(models.Model):
title = models.CharField(max_length=150)
author = models.CharField(max_length=100)
read = models.CharField(max_length=3)
def __unicode__(self):
return self.title + " / " + self.author + " / " + self.read
我找到了答案:
Django 1.5 has experimental support for Python 3, but the Django 1.5 tutorial is written for Python 2.X:
This tutorial is written for Django 1.5 and Python 2.x. If the Django version doesn’t match, you can refer to the tutorial for your version of Django or update Django to the newest version. If you are using Python 3.x, be aware that your code may need to differ from what is in the tutorial and you should continue using the tutorial only if you know what you are doing with Python 3.x.
In Python 3, you should define a str method instead of a unicode method. There is a decorator python_2_unicode_compatible which helps you to write code which works in Python 2 and 3.
@python_2_unicode_compatible class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published')
def __str__(self):
return self.question For more information see the section str and unicode methods in the Porting to Python 3 docs.
最佳答案
您尚未定义(或未正确定义)Books
模型的 __unicode__()
方法:
5. Next, open up your models.py file and add these two lines of code-
def __unicode__(self):
return self.title + " / " + self.author + " / " + self.read
仅供引用,引自 docs :
The
__unicode__()
method is called whenever you call unicode() on an object. Django usesunicode(obj)
(or the related function,str(obj)
) in a number of places. Most notably, to display an object in the Django admin site and as the value inserted into a template when it displays an object. Thus, you should always return a nice, human-readable representation of the model from the__unicode__()
method.
关于django - 在管理员中我看到 "App_name object"但不是实际的对象名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18727460/
有没有办法为 Sinatra 获取 Django Admin 风格的网络管理员? 最佳答案 没用过,但通过谷歌很快就显示出来了:http://www.padrinorb.com/ 关于ruby - S
我正在开发一个 Wordpress 插件,它为不同的用户(管理员、编辑、作者、贡献者、订阅者)提供不同的权限。我已经能够使该插件在管理员面板或页面/末尾完美运行,但是当我以编辑身份登录时,我无法在他们
在为 Web 应用程序用例图建模时,为用户可以拥有的每个角色创建一个角色是否更好?或拥有一个角色、用户和一个具有特权的矩阵? guest < 用户 < 版主 < 管理员 1: guest 、用户、版主
Tibco Administrator GUI 在哪里获取应用程序和服务的状态? 在我的项目中,我需要读取 Tibco admin 中列出的所有服务的状态。我没有安装 Tibco hawk,我需要除
我们最近将我们的多域 magento 设置从共享主机迁移到专用服务器。 一切正常,但是当我尝试转到管理部分时,登录后出现任何 404 错误。 如果我从 url 中删除 index.php 似乎可以工作
我有一个多对多字段。我想限制管理员在其 M2M 小部件中显示的选择。 我有一个这样的模型: class A(models.Model): b_field = models.ManyToMany
我正在与其他几位同事一起使用 Azure。我们有一个共享的管理员帐户,我们所有人都可以访问该帐户(凭据)。几天前,当尝试使用管理员帐户登录 Azure 门户时,我们收到此消息:“需要更多信息。您的组织
如何使 Django 后端(和一些 View )在不同的域中可访问?是通过站点框架完成的吗? 最佳答案 创建 settings.py 的副本并使用该设置文件运行管理服务器。此外,创建 urls.py
我刚刚收到以某种方式在 Django 管理面板上显示数据的要求。实际上我有日志表,其中包含用户 ID 和它采取的操作。 class AuditTrail(models.Model): id = m
每当我访问我的网站地址/admin 时,就会出现此问题 Warning: mysqli::mysqli() [mysqli.mysqli]: (28000/1045): Access denied f
我一直在为 Django/Mysql 中的情况而苦苦挣扎。 在同时有主键和外键的表中有这一列。此列与中间表具有一对多关系。 这是与植物物种相关的状态列表。有些物种可以在多个州找到。 物种(表 1)列:
firebase 身份验证和 firebase 管理员有什么区别? 据我所知,firebase admin 具有身份验证功能,并且可以绕过安全性,这与 firebase 身份验证不同。 Firebas
我创建了一个 SonarQube 组 sonar-administrators-ldap 并映射到 LDAP sonar-administrators-ldap 。 sonar-administrat
我正在创建一个 Django 应用程序,其中所有模型都可以按照用户设置的顺序相互关联。我正在使用 GenericForeignKeys 设置所有这些。关键是我需要能够支持这些类型的关系/管理的多个集合
我无法使用我创建的任何 super 用户登录 Django 管理员。尝试创建新的 super 用户、更改密码等 - 这些进程中的任何一个都没有错误消息,但仍然无法登录。 我不确定它是否相关,但我也无法
我正在将我的 Django 项目前端从使用 jquery 转换为 angularjs与 Django Rest Framework以帮助使其成为单页应用程序。我已经用 angular 转换了大部分棘手
我正在尝试在我的管理页面中的某个 ModelView 上加载脚本: class CustomView(ModelView): # Neither approach works here:
我正在尝试在我的 rails 应用程序中设置设计。它运行良好,但现在我无法以任何用户身份登录,我收到“电子邮件或密码无效”。我想更深入地了解为什么它不进行身份验证。 是否有任何设计配置设置可以提供更多
我目前正在尝试在 drupal 中实现第二个(较低的)管理层。我通过同名模块为这些用户制作了一个额外的部分,以便他们可以拥有自己的主题等。我想在他们的页面部分中为这些二级或更低级别的管理员提供一个菜单
如何显示来自 API 服务器 React-admin 3.0 版的错误响应消息? 此变体不起作用 https://github.com/marmelab/react-admin/pull/871 en
我是一名优秀的程序员,十分优秀!