python-模型表单不是使用django模型表单自动生成的

2021-01-08 34点热度 0人点赞 0条评论

我使用模型表单创建Django表单,因为我希望自动创建表单,但创建此代码时,表单不会显示在index.html页面中。

型号.py

from django.db import models


class BaseCase(models.Model):
    base_case_name = models.CharField(primary_key=True, max_length=255)
    version = models.TextField(blank=True, null=True)
    default = models.TextField(blank=True, null=True)  # This field type is a guess.

    class Meta:
        managed = False
        db_table = 'base_case'

表格.py

from django import forms
from SFP.models import *


class BaseCaseForm(forms.ModelForm):
    class Meta :
        model = BaseCase
        fields='__all__'

视图.py

from django.shortcuts import render,redirect
from .models import *
from .forms import *

def addbc(self, request):
    bcform=BaseCaseForm(request.POST)
    bcform.save()
    basecasename = bcform.cleaned_data['post']
    version = bcform.cleaned_data['post']
    default = bcform.cleaned_data['post']
    bcform = BaseCaseForm()
    return redirect('index.html')
    args = {'bcform':bcform,
            'basecasename': basecasename,
            'version': version,
            'default' :default}

    return render(request, 'index.html', args)

index.html文件

<!DOCTYPE html>
<html>
    <head>
        <title>S&FP</title>
    </head>
    <body>
        <h1>Forms</h1>
          {% csrf_token %}
          {{ bcform }}
       <input type="submit" value="add">
    </body>
</html>

我认为这也很重要。

from django.conf.urls import url
from . import views

urlpatterns = [
    url(r'^$', views.index),
    url(r'^$', views.addbc),
]

我本来以为表单域是自动生成的,但它们不会出现!

查看隐藏内容需要支付:¥1
查看

未经允许不得转载!python-模型表单不是使用django模型表单自动生成的

本文地址:https://ans.52learn.online/2180

ANS52LEARN

DO BEST