標籤:rms return val from 後台 utils models ini util
一、HTML中 | safe 可在後台用以下方式處理
1 text = "<input type‘text‘ />"2 from django.utils.safestring import mark_safe3 text = mark_safe(text)
二、views.py操作
1 from django.shortcuts import render 2 3 from django import forms 4 from django.forms import fields,widgets 5 from app01 import models 6 class LoveForm(forms.Form): 7 price = fields.IntegerField() 8 user_id = fields.IntegerField( 9 # widget=widgets.Select(choices=[(1,‘alex‘),(2,‘xialv‘),(3,‘sb‘),])10 # 資料庫取值11 widget=widgets.Select()12 )13 # 設定動態綁定,隨時更新資料14 def __init__(self,*args,**kwargs):15 # super必須在前,拷貝所有的靜態欄位,複製給self.fields16 super(LoveForm,self).__init__(*args,**kwargs)17 self.fields[‘user_id‘].widget.choices = models.UserInfo.objects.values_list(‘id‘,‘username‘)18 19 def love(request):20 obj = LoveForm()21 return render(request,‘love.html‘,locals())
西遊之路——python全棧——Form組件欄位及動態綁定