0
我有型号: models.py如何保存用户的数据?
class UserProfile(models.Model):
user = models.OneToOneField(User, related_name='userprofile')
points = models.IntegerField(default=0)
urls.py
urlpatterns = [
url(r'^$', demo),
url(r'^demo/$', demo),
]
demo.html
<form action="" method="POST">
<button type="submit">+</button>
</form>
views.py
def demo(request):
if request.method == "POST":
# I don't understand how I can get "points" from the model "UserProfile"
#to add 1 and to save in the DB
return render(request, 'app/demo.html')
我想按一下用户的按钮点增加一个。我真的无法弄清楚。
我知道其他人已经提供了解决方案,但我真的建议您阅读[Django的文档(https://docs.djangoproject.com/en/1.11/)如果您还没有 – dspacejs