Django objects.get无法正常工作

时间:2017-12-11 23:16:25

标签: django

我在从数据库中提取数据时遇到问题。我试图通过我的数据库使用get函数在html中显示纽约洋基队(或任何美国联盟球队)。如果你们中的一个人可以指出为什么它可能不起作用,那将非常感激。谢谢。

榜/模型↓

from __future__ import unicode_literals

from django.db import models


class AlStandings(models.Model):
    team = models.CharField(db_column='TEAM', max_length=30, blank=True, null=True) 
    w = models.IntegerField(db_column='W', blank=True, null=True)  
    l = models.IntegerField(db_column='L', blank=True, null=True)  
    pct = models.DecimalField(db_column='PCT', max_digits=4, decimal_places=3, blank=True, null=True
    gb = models.DecimalField(db_column='GB', max_digits=65535, decimal_places=65535, blank=True, null=True) 
    rs = models.IntegerField(db_column='RS', blank=True, null=True)  
    ra = models.IntegerField(db_column='RA', blank=True, null=True)  
    diff = models.IntegerField(db_column='DIFF', blank=True, null=True)  
    home = models.CharField(db_column='HOME', max_length=7, blank=True, null=True) 
    road = models.CharField(db_column='ROAD', max_length=7, blank=True, null=True) 
    east = models.CharField(db_column='EAST', max_length=7, blank=True, null=True) 
    cent = models.CharField(db_column='CENT', max_length=7, blank=True, null=True)  
    west = models.CharField(db_column='WEST', max_length=7, blank=True, null=True)  
    l10 = models.CharField(db_column='L10', max_length=6, blank=True, null=True)  
    strk = models.CharField(db_column='STRK', max_length=3, blank=True, null=True)  

榜/网址

from django.conf.urls import url
from . import views

urlpatterns = [
    url(r'^$', views.index),
]

榜/视图

from django.shortcuts import render
from django.template.response import TemplateResponse
from standings.models import AlStandings

def index(request):
    data = AlStandings.objects.get(team= 'New York Yankees’)
    return TemplateResponse(request, 'standings/index.html', {"data": data})

榜/ index.html中

{% extends 'layout/layout.html' %}


{% block content %}
{{data.team}}
{% endblock %}

0 个答案:

没有答案