VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > Python基础教程 >
  • Django forms 主要的标签介绍

修改 forms.py

from django import forms as DForms
from django.forms import fields
from django.forms import widgets


class DetailForm(DForms.Form):
    user1 = fields.CharField(widget=widgets.PasswordInput)
    user2 = fields.CharField(widget=widgets.TextInput(attrs={'class': 'c1', 'placeholder': '用户名'}))
    user3 = fields.ChoiceField(choices=[(1, 'SH'), (2, 'BJ'), ])
    user4 = fields.IntegerField()
    user5 = fields.CharField(
        widget=widgets.Select(choices=[(1, 'SH'), (2, 'BJ'),])
    )
    user6 = fields.IntegerField(
        widget=widgets.Select(choices=[(1, 'SH'), (2, 'BJ'), ])
    )
    user7 = fields.IntegerField(
        widget=widgets.RadioSelect(choices=[(1, 'SH'), (2, 'BJ'), ])
    )

修改 urls.py

path('detail.html', views.detail),

修改 views.py

from django.shortcuts import render, HttpResponse
from django import forms
from app01 import forms


def detail(request):
    obj = forms.DetailForm(request.POST)
    obj.is_valid()
    print(obj.clean())

    return render(request, 'detail.html', {'obj': obj})

修改 detail.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <form action="detail.html" method="post">
        <div>user1:{{ obj.user1 }}</div>
        <div>user2:{{ obj.user2 }}</div>
        <div>user3:{{ obj.user3 }}</div>
        <div>user4:{{ obj.user4 }}</div>
        <div>user5:{{ obj.user5 }}</div>
        <div>user6:{{ obj.user6 }}</div>
        <div>user7:{{ obj.user7 }}</div>
        <input type="submit" value="提交">
    </form>
</body>
</html>



相关教程