小编Gau*_*ker的帖子

Django admin:“ bool”对象没有属性“ startswith”

我正在使用django_smart_select软件包。我在尝试使用链式选择选项的模型中收到以下错误。

AttributeError at /admin/tags/tag/add/
'bool' object has no attribute 'startswith'
Request Method: GET
Request URL:    http://127.0.0.1:8000/admin/tags/tag/add/
Django Version: 1.11.4
Exception Type: AttributeError
Exception Value:    
'bool' object has no attribute 'startswith'

Error during template rendering

In template C:\Users\gautammandewalker\Envs\django01\lib\site-
packages\django\contrib\admin\templates\admin\base.html, error at line 3
'bool' object has no attribute 'startswith'
1   {% load i18n static %}<!DOCTYPE html>
2   {% get_current_language as LANGUAGE_CODE %}{% get_current_language_bidi 
as LANGUAGE_BIDI %}
3   <html lang="{{ LANGUAGE_CODE|default:"en-us" }}" {% if LANGUAGE_BIDI 
%}dir="rtl"{% endif %}>
4   <head>
5   <title>{% …
Run Code Online (Sandbox Code Playgroud)

django

4
推荐指数
1
解决办法
1483
查看次数

如何在django-import-export中只有CSV,XLS,XLSX选项?

我为我的项目实现了django-import-export.

默认情况下,它为导入和导出提供了许多文件格式选项.

如何将文件格式限制为仅限CSV,XLS和XLSX?

在此输入图像描述

django django-import-export

4
推荐指数
2
解决办法
1630
查看次数

管理员中的Django模型pre_save验证

以下是我的模型:

class Product(models.Model):
    product_title = models.CharField(max_length=100, null=False, 
verbose_name='Product title')
    product_description = models.TextField(max_length=250, 
verbose_name='Product description')
    product_qty = models.IntegerField(verbose_name='Quantity')
    product_mrp = models.FloatField(verbose_name='Maximum retail price')
    product_offer_price = models.FloatField(verbose_name='Selling price')

def validate_produce_offer_price(sender, instance, **kwargs):
    if instance.product_offer_price > instance.product_mrp:
        from django.core.exceptions import ValidationError
        raise ValidationError('Product offer price cannot be greater than 
Product MRP.')


pre_save.connect(validate_produce_offer_price, sender=Product)
Run Code Online (Sandbox Code Playgroud)

我想在保存模型之前验证product_offer_price.验证错误正在成功引发,但是在调试器创建的异常页面上.如何在管理员本身的表单上显示错误,就像管理表单提出的其他错误一样?

在更改现有数据期间引发的异常 添加新数据时引发异常

django django-models django-admin

1
推荐指数
1
解决办法
1778
查看次数