2013-02-16 64 views
1

我试图从django-registration插入注册表单模板在另一个html文档中。 原来的注册模板它工作得很好,用户保存在数据库中:Django - 扩展注册表单模板不显示字段

这是我尝试在其他任何使用{% extend registration/myRegistrationFormTemplate.html %}的html文档中插入注册表单时发生的情况。字段不显示,提交按钮不起作用。

http://oi50.tinypic.com/6fyujl.jpg

此外,这是发生了什么,当我尝试使用jQuery方法.load加载myRegistrationFormTemplate.html。字段显示,但提交按钮不起作用。

http://oi45.tinypic.com/5vorc9.jpg

的问题是:为什么会这样?以及通常的做法是什么?

+1

相关标签是'extend'而不是'extend'。另外,teplate的扩展是用于创建一个框架模板并使用它创建页面而不重复相同的代码块(如CMS模板中的'haader'和'footer')。在渲染模板时,您的视图是否在模板中发送了所需的“form”对象? [关于模板继承](https://docs.djangoproject.com/en/1.4/topics/templates/#template-inheritance) – FallenAngel 2013-02-16 14:41:22

回答

0

感谢FallenAngel你是对的,我错过了视图信息。谢谢你告诉我关于“包括”almalki,现在它所有的工作都是正确的。在我的项目中,在这个视图和一个jQuery模式窗口中使用2种形式。为了简化我的解决方案,我只使用一种形式。我希望这对某人有用。

SOLUTION: 查看模板,你会包括形式

def patrimonio_view(request, 
    template_name='home/patrimonio.html'): 

#OTHER DB QUERYS 
pat = patrimonio.objects.all() 
ciu = ciudad.objects.all() 

if request.method == 'POST': 
    if "Registrar_usuario" in request.POST: 
     #USER REGISTRATION FORM RELATIVE 
     return register_usuario() 

    if "Registrar_comerciante" in request.POST: 
     #MERCHANT REGISTRATION FORM RELATIVE 
     return register_comerciante() 

#RENDER 
return render_to_response(template_name,{ 
    'patrimonio':pat, 
    'ciudad':ciu, 
}, context_instance=RequestContext(request)) 

urls.py

url(r'^patrimonio/$','patrimonio_view', 
{'backend_registro_usuario': 'Hesperides.apps.accounts.regbackend_usuario.DefaultBackend','form_class_usuario':RegistrationForm_usuario}, name='vista_patrimonio'), 
模板

你将包括下列形式:

{% include "registration/registration_form_usuario.html" %}