- models.py
- views.py
- urls.py
- login.html
- 访问
class User(models.Model):
username = models.CharField(max_length=32)
password=models.CharField(max_length=32)
email = models.EmailField(max_length=32)
views.py
from django.shortcuts import render,HttpResponse,redirect
# Create your views here.
from django import forms
class UserForm(forms.Form):
# min_length:不能小于最小字段长度;max_length:不能大于最长字段长度;label:前端展示,便于用户阅读,若不配置则显示username
username = forms.CharField(min_length=3,max_length=8,label='用户名')
password = forms.CharField(min_length=3,max_length=8,label='密码')
email = forms.EmailField(label='邮箱地址')
def login(request):
form_obj = UserForm()
return render(request,'login.html',locals())
urls.py
from django.contrib import admin
from django.urls import path
# 导入bms项目
from bms import views
urlpatterns = [
path('admin/', admin.site.urls),
path('login/',views.login)
]
login.html
Title
访问
重启项目,访问http://127.0.0.1:8000/login/
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)