【问题标题】:Notifications system has issues通知系统有问题
【发布时间】:2016-01-25 00:52:54
【问题描述】:

我不确定这个通知系统看起来会发生什么,这是错误

int() argument must be a string, a bytes-like object or a number, not 'SimpleLazyObject'

Views.py

def index(request):
    notifi = Notificaciones.objects.filter(user=request.user, Estado=False)
    if request.method == 'POST':
        form = RegistroUserForm(request.POST, request.FILES)
    else:
        form = RegistroUserForm()
    context = {
        'form': form,
        'notifi': notifi
    }

    return render(request,'app/index.html',context)

Models.py

class Notificaciones(models.Model):
    user = models.ManyToManyField(User)
    Tipo_de_notificaciones = ( (1,'Ofertas'),(2,'Error'),(3,'Informacion'))
    Tipo = models.IntegerField('Tipo de notificacion',choices=Tipo_de_notificaciones, default=3,)
    titulo = models.CharField("Nombre de la notifiacion",max_length=50)
    mensaje = HTMLField("Descripcion de la notificacion")
    imagen = models.ImageField("Imagen de la notificacion",upload_to="notificaciones")
    Fecha_Caducidad_notificacion = models.DateTimeField("Fecha de caducidad de la notificacion",auto_now_add=False)
    Estado = models.BooleanField("Estado de la notificacion", default=False)
    class Meta:
        verbose_name = 'Notificacion'
        verbose_name_plural = 'Notificaciones'
    def __str__(self):
        return self.titulo

@receiver(post_save, sender=User)
def mensaje_bienvenida(sender, **kwargs):
    if kwargs.get('creado', False):
        Notificaciones.objects.create(user=kwargs.get('instance'),
                                      titulo= "Bienvenido a la plataforma de Vulpini.co",                                      
                                      mensaje= 'Gracias por registrarte'
            )

Notificaciones.html

{% if notifi.count > 0 %}
        {% for notifi in notifi %}
           <ul>
              <li>
                {{ notifi.Tipo }}
                {{ notifi.titulo }}
                <img src="{{  notifi.imagen.url }}" alt="{{ notifi.titulo }}"/>
                {{ notifi.mensaje }}
                {{ notifi.Fecha_Caducidad_notificacion }}
              </li>
            </ul>
        {% endfor %}
    {% endif %}

为什么显示错误,如果两天前工作并且我没有更改任何内容。 帮帮我,谢谢

【问题讨论】:

  • 你能发布回溯吗?您没有在该代码中调用 int,因此我们无法判断错误发生在哪里。

标签: python django


【解决方案1】:

你有没有在你的views.py中尝试过这样的事情?

notifi = Notificaciones.objects.filter(user=request.user.id, Estado=False)

编辑:

也许之前的这篇文章对你有帮助。 django: Purpose of django.utils.functional.SimpleLazyObject?

或者看看我发现了什么,这也可能会有所帮助: Django int() argument must be a string or a number

希望这会有所帮助。 :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-26
    • 2017-03-28
    • 1970-01-01
    • 1970-01-01
    • 2013-03-31
    • 1970-01-01
    • 2011-07-18
    • 2013-05-08
    相关资源
    最近更新 更多