美文网首页
5(write to database)

5(write to database)

作者: EudeMo | 来源:发表于2015-11-12 20:29 被阅读0次

    修改views.py

    from django.shortcuts import render
    from .forms import AppNameForm
    # Create your views here.
    def home(request):
        title='home'
        #没有括号里的参数就不能写入数据库,还不能运行clean_email
        form = AppNameForm(request. POST or None )
        context = {
                "title" : title,
                "form" : form,
            }
        if form.is_valid():
            instance = form.save(commit=False)
            if not instance.attr:#在这里修改值
                instance.attr = "default attr"
            instance.save()#写入数据库
            context = {
                "title" : "thank you",
            }
        return render(request, "home.html",context)
    

    相关文章

      网友评论

          本文标题:5(write to database)

          本文链接:https://www.haomeiwen.com/subject/finhhttx.html