M
M
Maxim Shelkov2020-04-21 21:57:52
Django
Maxim Shelkov, 2020-04-21 21:57:52

'Ba' object has no attribute 'print' Django error, how to solve?

Code Models

from django.db import models
class Bb(models.Model):
    title = models.CharField(max_length = 50)
    content = models.TextField(null = True, blank = True)
    price = models.FloatField( null=True, blank = True)
    published = models.DateTimeField(auto_now_add=True, db_index=True)

Views code
from django.http import HttpResponse
from .models import Ba

def index(request):
    s = 'Список объявлений\n\r\n\r\n\r'
    for b in Ba.objects.order_by('-published'):
        s += 'Название: ' + b.title + '\n\r\n\r' + 'Описание: ' + b.content + '\n\r\n\r' + 'Цена: ' + b.print
    return HttpResponse(s, content_type = 'text/plain; charset=utf-8')


In the Database there are names of cars, description and price.

I get an error when starting the server Thank you for your help 'Ba' object has no attribute 'print'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2020-04-21
@BickDem

'Цена: ' + b.price

V
Vladimir Kuts, 2020-04-21
@fox_12

Well, firstly - you declare and bring the model Bb, and import the model Ba
Well, and secondly - if you take the model Bb for the model Ba - then it really does not have a print property
, maybe 'price' did you mean?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question