如何在Django中编写Python代码

Sur*_*oor 0 python django

这是一个令人尴尬的简单问题.我正在尝试理解如何在我正在构建的第一个Django应用程序中合并一个简单的Python函数.这是我的views.py文件...

from django.shortcuts import render
from noticeboard.models import Listings
from django.views import generic
from django.template import Context

class IndexView(generic.ListView):
    template_name = 'listings/index.html'
    context_object_name = 'latest_listings'

    def get_queryset(self):
        return Listings.objects.order_by('-pub_date')

class DetailView(generic.DetailView):
    model = Listings
    template_name = 'listings/listings_detail.html'
    context_object_name = 'listing'
Run Code Online (Sandbox Code Playgroud)

在清单模型中,我有以下字段:

listing = models.CharField(max_length=50)
Run Code Online (Sandbox Code Playgroud)

我想写一个函数来确保列表变量都是大写 - 我知道如何编写函数 - 我只是不知道如何将它合并到views.py文件中!

jpi*_*pic 5

为什么不使用upper模板过滤器

无需编写任何纯python来以大写形式显示视图上下文变量...