# coding=utf-8 from django.conf.urls import url, include from stu import viewsurlpatterns = [url(r"^$", views.index_view),# url(r"^register/",include('stu.urls'))]
4.register.html编写
{% csrf_token %}
5.model模型创建models.py
from django.db import models# Create your models here.# 定义模型类,需要继承于models.Modelclass Student(models.Model):sname = models.CharField(max_length=30, unique=True)spwd = models.CharField(max_length=30)# class Meta:# db_table="t_stu" #应用名_模型名,小写
6.创建views.py视图函数
from django.http import HttpResponse from django.shortcuts import render# Create your views here. from stu.models import Studentdef index_view(request):m = request.methodif m == "GET":return render(request, 'register.html')else:uname = request.POST.get("uname", "")upwd = request.POST.get("pwd", "")if uname and upwd:stu = Student(sname=uname, spwd=upwd)stu.save()return HttpResponse("注册成功")return HttpResponse("注册失败")