🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] >[success] # views.py ~~~ from django.shortcuts import render,redirect,reverse from . import models from . import forms # Create your views here. def index(request): students = models.Student.objects.all() if request.method == "POST": form = forms.StudentForm(request.POST) if form.is_valid(): clean_data = form.cleaned_data models.Student.objects.create( name=clean_data['name'], sex=clean_data['sex'], email=clean_data['email'], profession=clean_data['profession'], qq=clean_data['qq'], phone=clean_data['phone'] ) return redirect(reverse("index")) else: form = forms.StudentForm() context = { 'students': students, 'form': form, } return render(request, 'index.html', context=context) ~~~ >[danger] ##### 技巧根据名字获取url-reverse ~~~ redirect(reverse("index")) ~~~