“_wrapped_view()至少需要1个参数”错误是什么意思?

时间:2012-05-31 19:26:37

标签: python django django-templates django-views

我正在将Django表单数据呈现给模板,但每当我访问该url时,它都会向我显示此错误:

_wrapped_view() takes at least 1 argument (0 given)

views.py中的方法:

 @login_required                              
 def subnet_network_detail(request):
     if request.method == 'POST':
         form = NetworkCreateForm(request.POST)
         if form.is_valid():
             subnet = form.data['Subnet_Address']
             ip = form.data['IP_Address']
             user_hosts = get_hosts(user=request.user)
             hosts_list = host_subnet(user_hosts,subnet,ip)
             import pdb;pdb.set_trace()
     extra_context = {
         'hosts_list': hosts_list
         }
     return direct_to_template(request, 'networks/subnet_network.html',extra_context)

和urls.py:

  url(r'^network/netmask/select/$',
     'subnet_network_detail', name='subnet_network_detail')

我从有关此错误的其他问题中读到了但没有任何想法。怎么解决?

1 个答案:

答案 0 :(得分:2)

direct_to_template旨在用于urls.py

url(r'^network/netmask/select/$', 'direct_to_template', {'template':'networks/subnet_network.html'}, name='subnet_network_detail')

您应该在视图中使用renderrender_to_response

如果您使用的是django 1.3或更高版本,则可以使用:

from django.shortcuts import render
...
return render('networks/subnet_network.html', extra_context)

或者如果您使用的是早期版本:

from django.shortcuts import render_to_response
from django.template import RequestContext
...
return render_to_response('networks/subnet_network.html', extra_context, RequestContext(request))