Django连接CreateView,自动填充隐藏inpu

2024-04-19 21:56:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图创建2个CreateView(step1,step2),在第一个视图中我创建了一个用户(djangomodels.user)。你知道吗

我的第一步视图:

class UserStep1(CreateView):
    model = User
    fields = [
        'username',
        'password',
    ]

    def get_success_url(self):
        return reverse('step-2',args=(self.object.id,))

    template_name = 'step1.html'

在第一个表单提交之后,我将用户重定向到第二个步骤表单。你知道吗

我的第二步视图:

class UserStep2(CreateView):
    model = UserMeta
    fields = [
        'auth', # This is the input that I want to autocomplete with url <pk>
        'zip_code',
        'city',
    ]

    template_name = 'step2.html'

我的网址:

url(r'^user/create/step1/$', UserStep1.as_view(), name='step-1'),
url(r'^user/create/step2/(?P<pk>[0-9]+)/$', UserStep2.as_view(), name='step-2'),

问题

我要通过考试用户id从第一步到第二步,并自动填充“auth”输入。。我该怎么做?你知道吗


Tags: 用户nameself视图idurlfieldsmodel