找不到任何参数的“contentsoccasionstep1”则相反。尝试了1个模式:['myapp/create/step1/(?P<current\u object\u id>\\d+$)]

2024-05-19 21:14:48 发布

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

在我的django应用程序中,我试图在用户提交表单后将其重定向到视图

我收到的错误

Reverse for 'contents-occasion-step-1' with no arguments not found. 1 pattern(s) tried: ['myapp/create/step-1/(?P<current_object_id>\\d+)$']

我从中重定向视图的功能

def create_object(request):
    if request.method == 'POST':
        form = DataBase(request.POST)
        if form.is_valid():
            form_data = form.save(commit=False)
            form_data.created_by = request.user
            form_data.save()

            # save current object id in the session
            request.session['current_object_pk'] = form_data.pk

            manipulation_function(request, form_data)

            return redirect('contents-occasion-step-1', current_object_id = form_data.pk)
    else:
        form = DataBase()
    return render(request, 'my/create_object.html', {
        'form': form
    })

我的URL.py

url(r'myapp/create/step-1/(?P<current_object_id>\d+)$', views.contents_occasion_step_1, name='contents-occasion-step-1')

我的观点。py

def contents_occasion_step_1(request, current_object_id):
    """View
    """
    [My code below]

    return render(request, 'myapp/mytemplate.html', {
        'variable_for_template': request.session['variable_for_template']

    })

Tags: formidfordataobjectrequestsessionsave