我正在将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')
我从有关此错误的其他问题中读到了但没有任何想法。怎么解决?
答案 0 :(得分:2)
direct_to_template
旨在用于urls.py
:
url(r'^network/netmask/select/$', 'direct_to_template', {'template':'networks/subnet_network.html'}, name='subnet_network_detail')
您应该在视图中使用render
或render_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))