django在数据表视图中提交表单

时间:2015-10-27 16:56:05

标签: django mongodb

我正在尝试创建一个带有数据表视图的页面,并提供一个表单,我正在使用mongodb。 当我提交表格时,我收到错误。

我在views.py中使用的代码:

class agents(XEditableDatatableView):
model = Agent
template_name = 'add_agents.html'
datatable_options = {
    'columns':[
               ('Name','name'),
               ('IP','ip_address'),

    ],
}

@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
    return super(agents, self).dispatch(*args, **kwargs)

def get_queryset(self):
    queryset = super( agents, self ).get_queryset()
    print "------------------------------------"
    if self.request.method=="POST":
        req=self.request.POST
        newAgent=Agent(name=req['name'],ip_address=req['ip_address'])
        newAgent.save()
    print queryset
    print "------------------------------------"
    return queryset

def get_context_data(self, **kwargs):
    context = super( agents, self ).get_context_data( **kwargs )
    context['form']=AgentForm

    print "**********************"
    print context
    print "**********************"
    return context

enter image description here

enter image description here

0 个答案:

没有答案