這是一個令人尷尬的簡單問題。我試圖瞭解如何在我正在構建的第一個Django應用程序中包含一個簡單的Python函數。這是我的views.py文件...如何在Django中編寫Python代碼
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'
在信息模型中,我有以下領域:
listing = models.CharField(max_length=50)
我想編寫一個函數,確保上市變量是所有上案例 - 我知道如何編寫函數 - 我只是不知道如何將它整合到views.py文件中!
你說你想「確保列表變量都是大寫」 - 你的意思是你打算接受輸入並希望在保存之前將其大寫?您在此處使用的視圖處理顯示數據庫中已存在的信息,但不處理創建或更新。 –