Im은 데이터베이스에서 내 값을 1 씩 증가시켜 페이지에 표시하는 간단한 버튼을 만들려고합니다."Like"카운터, 장고를 클릭하여 값을 증가 시키십시오.
나는 Django - How to increment integer field from user input?에서 뭔가를 발견했지만 문제가 해결되지 않습니다.
views.py에 내 코드 :
if request.method == 'POST':
id = request.POST.get('slug')
vote = request.POST.get('voo')
glosy = request.POST.get('glosy')
git = Photo.objects.all().filter(pk=id, votes = vote)
vote = int(vote)+1
p = Photo.objects.get(pk=id)
print p.votes3
p.votes3 += 1
print p.votes3
p.save()
Photo.objects.all().filter(pk=id).update(votes3=10)
및 템플릿에 내 코드 :
{% extends "photologue/root.html" %}
{% load photologue_tags i18n %}
{% load comments %}
{% block title %}{{ obj.title }}{% endblock %}
{% block content %}
{% load static %}
<script src="{% static 'js/pinol-ajax.js' %}"></script>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '876940702346526',
xfbml : true,
version : 'v2.2'
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<div class="row col-lg-12">
<h1 class="page-header">{{ obj.title }}</h1>
<p class="muted"><small>{% trans "Published" %} {{ obj.date_added }}</small></p>
</div>
<div class="row">
<div class="col-md-6">
{% if obj.caption %}<p>{{ obj.caption|safe }}</p>{% endif %}
<a href="{{pho.image.url}}" data-lightbox="roadtrip" alt = "">
<img src="{{ pho.get_display_url }}" class="thumbnail" alt="{{ obj.title }}"></a>
<br>
<!-- <button id="likes" data-catid="{{obj.title}}" class="btn btn-primary" type="button"> Like </button> {{ pho.votes }} {{ object.view_count }} -->
<strong id="like_count">{{ pho.votes }}</strong> people like this photo
{% if user.is_authenticated %}
<form action="" method="post">
{% csrf_token %}
<button type="submit" value="preview" name="Preview">HUEHUE</button>
{% endif %}
<div class="fb-share-button" data-layout="button_count"></div>
</a>
</div>
<div class="col-md-6">
{% if pho.public_galleries %}
<p>{% trans "This photo is found in the following galleries" %}:</p>
<table>
{% for gallery in pho.public_galleries %}
<tr>
<td>{% previous_in_gallery pho gallery %}</td>
<td class="text-center"><a href="">{{ gallery.title }}</a></td>
<td>{% next_in_gallery pho gallery %}</td>
</tr>
{% endfor %}
</table>
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}fluent_comments/css/ajaxcomments.css" />
<script type="text/javascript" src="{{ STATIC_URL }}fluent_comments/js/ajaxcomments.js"></script>
<div class="fb-like" data-href="{{request.META.HTTP_HOST}}" data-layout="standard" data-action="like" data-show-faces="true" data-share="true"></div>
<div class="fb-comments" data-href="{{request.META.HTTP_HOST}}" data-numposts="5" data-colorscheme="light"></div>
<!-- {{request.META.HTTP_HOST}}{{request.get_full_path}} -->
{% render_comment_list for pho %}
{% if user.is_authenticated %}
{% render_comment_form for pho %}
{% else %}
Zaloguj się aby dodawać komentarze! :)
{% endif %}
{% endif %}
{% endblock %}
페이지가 새로 고쳐 지지만 페이지의 카운터가 증가하지 않습니다. 귀하의 솔루션을 점검하고 어떤 일이 발생했는지 알려주십시오. – bMh
작동하지 않는 경우 전체 템플릿 및보기를 제공하십시오. – Serafeim
양식 동작이 변경된 후 오류가 발생했습니다 : " '(' ',)'및 '{' '인수가있는'photo_det '에 대해 역방향으로 실행했습니다.} 0 패턴 시도 : []" – bMh