Уведомления

Группа в Telegram: @pythonsu

#1 Ноя. 27, 2016 14:29:28

Jaison
Зарегистрирован: 2016-11-27
Сообщения: 2
Репутация: +  0  -
Профиль   Отправить e-mail  

'bool' object has no attribute 'save'

Как исправить код?

'bool' object has no attribute ‘save’

 def favorite(request, account_id):
    sql_db = get_object_or_404(Account, id = account_id)
    try:
        selected = sql_db.account_id_set.get(pk = request.POST['favorite'])
    except (KeyError, Account_id.DoesNotExist):
        return render(request, 'account/account.html', {'sql_db':sql_db,
                                                        'error_message':'Signal False'})
    else:
        sql_db.is_favorite = True
        sql_db.is_favorite.save()
        return render(request, 'account/account.html', {'sql_db':sql_db})

 {% if error_message %}
    <p>{{ error_message }}</p>
{% endif %}
<!doctype html>
<html lang = 'en'>
<body>
<p><img src="{{ sql_db.avatar }}"/></p>
<p><strong>Username:</strong>{{ sql_db.username }}</p>
<p><strong>Password:</strong>{{ sql_db.password }}</p>
<p><strong>Email:</strong>{{ sql_db.email }}</p>
<p><strong>Year:</strong>{{ sql_db.year }}</p>
<p><strong>Month:</strong>{{ sql_db.month }}</p>
<p><strong>Day:</strong>{{ sql_db.day }}</p>
<form action="{% url 'account:favorite' sql_db.id %}" method = "post">
    {% csrf_token %}
    <input type="radio" id="favorite1" name="favorite" value="1"/>
    <label for="favorite1">Remember it?
        {% if sql_db.is_favorite %}
            <img src="https://cdn2.iconfinder.com/data/icons/32pxmania/misc_57.png"/>
        {% endif %}
    </label>
    <input type="submit" value="Remember"/>
</form>
</body>
</html>

Отредактировано Jaison (Ноя. 27, 2016 14:31:31)

Офлайн

#2 Ноя. 27, 2016 14:34:05

FishHook
От:
Зарегистрирован: 2011-01-08
Сообщения: 8312
Репутация: +  568  -
Профиль   Отправить e-mail  

'bool' object has no attribute 'save'

Ну внимательнее же, ну!

 sql_db.is_favorite.save()

 sql_db.save()



Офлайн

#3 Ноя. 27, 2016 14:55:47

Jaison
Зарегистрирован: 2016-11-27
Сообщения: 2
Репутация: +  0  -
Профиль   Отправить e-mail  

'bool' object has no attribute 'save'

Ups. , спасибо за ответ.

Офлайн

Board footer

Модераторировать

Powered by DjangoBB

Lo-Fi Version