0

我试图从 html 文件传递​​一个变量并试图在我的视图中访问它..但我得到了这个错误..--signup_vol_position 完全需要 2 个参数(给定 1 个)

视图.py

def signup_vol_position(request,comments):
        pdb.set_trace()
        if request.method == 'POST':
                print('if')
        else:
                print('else')
        teamrel = VolunteerRequirement.objects.values_list('teamrelation',flat=T
        vollist = VolunteerRequirement.objects.order_by('teamrelation')
        variable = RequestContext(request, {'vollist': vollist,'teamrel':teamrel
        return render_to_response('signups/volunteer_list.dmpl',variable)
        #variable = RequestContext(request,{'comments':comments}
        #return render_to_response('sfp.view',variable)

.html 文件

<table>

{% for v in vollist %}
{% ifchanged  v.teamrelation %}
<tr>
<th colspan=7 align="left"><h3><a name="{{ v.teamrelation }}"> {{v.teamrelation}} </a> </h3></th>
</tr>
{% endifchanged %}


<tr>
        <th colspan=4 align="left"><label for="id_Volposition">Volunteer Position:</label></th>
        <th colspan=.5 align="left"><a href="/signups/volposition/{{ v.position }}" class="username" <u>{{ v.volposition }}</u></a></th>
<tr> <td colspan="2" height="2" style="display:none">&nbsp;</td> </tr>
</tr>

网址.py

urlpatterns = patterns('',
   (r'^new/$',                           sfp.view),
   (r'^volunteer/$',     volunteer_page),
   (r'^vollist/$', volunteer_list),
   (r'^volcont/$', volunteer_contact),
   (r'^volposition/$',signup_vol_position)
)
4

1 回答 1

0

根据您的定义,除了请求对象之外,函数 signup_vol_position 还需要一个参数。但是,在 urls.py 中,您没有考虑到该论点。应该是这样的

(r'^volposition/(.+)$',signup_vol_position)

看看这是否有效。

于 2013-06-06T09:31:21.753 回答