You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python 2.7 Django 1.9传递2个参数失败,报submission()参数不匹配错误

Hey there, let's work through this argument error you're stuck on. That submission() takes exactly 2 arguments (1 given) message makes it clear: your view function is expecting two parameters, but only one is being passed when the form submits. Let's break down the most likely fixes for your Django 1.9 + Python 2.7 setup:

1. Check your view function definition

First, take a look at how you’ve defined the submission view in your views.py. If it looks like this:

def submission(request, extra_param):
    # Your view logic here

That means it needs two arguments: request (which Django automatically passes) and extra_param. If your URL or form action isn’t sending that second parameter, you’ll get this error.

If you don’t actually need that second parameter, just strip it out to match what’s being passed:

def submission(request):
    # Your view logic here

2. Verify your URL configuration (urls.py)

If you do need that second parameter in the view, check your urls.py to make sure the URL pattern is set up to capture it, and that your form is passing it correctly.

For example, if your URL pattern looks like this (capturing a numeric ID):

url(r'^submission/(?P<item_id>\d+)/$', views.submission, name='submission'),

Then your form’s action needs to include that item_id parameter when using the {% url %} template tag:

<form method="post" action="{% url 'submission' item_id=your_value_here %}" enctype="multipart/form-data">

Replace your_value_here with the actual value you need to pass—this could be a context variable like {{ object.id }} if you’re working with a database object.

If your URL pattern doesn’t require a parameter, but your view still expects two, that’s a mismatch. Either adjust the view to only take request, or update the URL pattern to capture the required parameter.

3. Double-check the form’s action tag

From your submission.html snippet, your form action is just {% url 'submission' %}. If your view expects a second argument, this template tag isn’t providing it—so Django only passes the request object, hence the "1 given" error.

You can quickly debug this by rendering the template and checking the raw HTML output: if the action URL is something like /submission/ (without an extra parameter segment), that’s the problem. Fix the {% url %} tag to include all required arguments for your named URL.

Quick test to narrow things down

To confirm where the issue lies, temporarily modify your view to accept an optional parameter:

def submission(request, extra_param=None):
    print("Request object:", request)
    print("Extra parameter:", extra_param)
    # Rest of your view code

If extra_param prints None, you know the parameter isn’t being passed from the URL or form action—so you can focus on fixing that part.

内容的提问来源于stack exchange,提问作者dvd818

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:54:59