Django- Stuck并且无法获取要在网页上显示的数据

时间:2017-12-15 13:43:35

标签: python django

这是我的问题。我可以在我的统计页面和主页上显示我的其他一个表(我没有在这里显示的统计表)中的数据。这是我第一次能够让它工作,(我是Django的新手)。然后我在我的数据库(Alstandings表)中创建了另一个表,我做了一个应用程序,因为我想要一个排名页面。出于某种原因,我无法从我的Alstandings表中获取数据以显示在排名页面上。据我所知,我认为我复制了这个过程,但也许我错过了一些我不知道的事情。是的,我已在我的设置中注册了该应用程序。我现在没有收到任何错误。如果有人对如何使其发挥作用有任何宝贵意见,请回复。对你的帮助表示感谢。谢谢。

积分/模型

from django.db import models


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

class Meta:
    managed = False
    db_table = 'AlStandings'

榜/ index.html中

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


{% block content %}

<table>
    <tr>
        <th>Team</th>
    </tr>
    {% for index in data %}
    <tr>
        <td>{{ index.team }}</td>
    </tr>
    {% endfor %}
</table>
{% endblock %}

榜/网址

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.all()
    return TemplateResponse(request, 'standings/index.html', {"data": data})

baseball / urls.py (与mysite / urls基本相同)

from django.conf.urls import include, url
from django.contrib import admin
from baseball import views as baseball_views

urlpatterns = [
    url(r'^$', baseball_views.index),
    url(r'^admin/', admin.site.urls),
    url(r'^standings/', include('standings.urls')),
    url(r'^stats/', include('stats.urls')),
]

baseball / views.py (与mysite / views基本相同)我能够让这个视图正常工作

from django.shortcuts import render
from django.template.response import TemplateResponse
from stats.models import MlbFielder


def index(request):
    data = MlbFielder.objects.all()
    return TemplateResponse(request, 'index.html', {"data": data})

0 个答案:

没有答案