我在尝试渲染时遇到一些不便 django-bootstrap-datepicker-plus小部件 根据 this answer .一切正常,但 Datepicker 没有出现。
我的 Django 版本是 1.10.7,我使用的第三方应用是:
pip install django-bootstrap3)pip install django-bootstrap-datepicker-plus)这是我的 forms.py,我覆盖了 DateInput 类以根据我的需要对其进行自定义。
from django import forms
from bootstrap_datepicker.widgets import DatePicker
class DateInput(DatePicker):
def __init__(self):
DatePicker.__init__(self,format="%Y-%m-%d")
class UserUpdateForm(forms.ModelForm):
class Meta:
widgets = {
'date_of_birth': DateInput(), # datepicker
'creation_date': DateInput(), # datepicker
}
fields = ("other fields", "date_of_birth", "creation_date", "other fields",)
model = get_user_model()
然后在我的模板表单中,我有一些名为 layout.html 的基本主模板,我的模板 user_form.html 我想在其中呈现上面提到的表单字段.所有这些模板都有一些 div 和 html 结构,您可以在 user_form.html 文件中看到 here .
在我的 settings.py 的 Bootstrap 设置中,我必须将 include_jquery 选项设置为 True
当我转到表单页面时,date_of_birth 字段未呈现为 日历日期选择器,它呈现为输入类型文本,用户应在其中以特定格式手动输入日期。
在我的 layout.html 中,我将一些额外的 cdn jQuery 资源调用到其他东西。
[下面的评论比这次编辑要早得多]
最佳答案
尝试在您的 base.html 模板中添加这些链接标签并从中扩展到 html 模板表单:
<link href="//cdn.bootcss.com/bootstrap-datetimepicker/4.17.44/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
<script src="//cdn.bootcss.com/jquery/3.0.0/jquery.min.js"></script>
<script src="//cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="//cdn.bootcss.com/moment.js/2.17.1/moment.min.js"></script>
并添加 {{ form.media }} 到您的模板表单中,例如:
<form class="mt-3" action="" method="post">{% csrf_token %}
{{ form.as_p }}
{{ form.media }}
<div class="text-center">
<input class="btn btn-primary btn-block" type="submit" value="Update" />
</div>
</form>
这解决了我使用 django-bootstrap-datepicker-plus 的问题。该软件包需要更详细的文档,简单且带有示例。但是一旦您开始配置它,它就会工作得很好。
关于javascript - Django 表单 - django-bootstrap-datepicker-plus 不呈现日期选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48576784/
我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib
我有一个ModularSinatra应用程序,我正在尝试将Bootstrap添加到应用程序中。get'/bootstrap/application.css'doless:"bootstrap/bootstrap"end我在views/bootstrap中有所有less文件,包括bootstrap.less。我收到这个错误:Less::ParseErrorat/bootstrap/application.css'reset.less'wasn'tfound.Bootstrap.less的第一行是://CSSReset@import"reset.less";我尝试了所有不同的路径格式,但它
我有一个服务模型/表及其注册表。在表单中,我几乎拥有服务的所有字段,但我想在验证服务对象之前自动设置其中一些值。示例:--服务Controller#创建Action:defcreate@service=Service.new@service_form=ServiceFormObject.new(@service)@service_form.validate(params[:service_form_object])and@service_form.saverespond_with(@service_form,location:admin_services_path)end在验证@ser
我是HanamiWorld的新人。我已经写了这段代码:moduleWeb::Views::HomeclassIndexincludeWeb::ViewincludeHanami::Helpers::HtmlHelperdeftitlehtml.headerdoh1'Testsearchengine',id:'title'hrdiv(id:'test')dolink_to('Home',"/",class:'mnu_orizontal')link_to('About',"/",class:'mnu_orizontal')endendendendend我在模板上调用了title方法。htm
我遇到了一个非常奇怪的问题,我很难解决。在我看来,我有一个与data-remote="true"和data-method="delete"的链接。当我单击该链接时,我可以看到对我的Rails服务器的DELETE请求。返回的JS代码会更改此链接的属性,其中包括href和data-method。再次单击此链接后,我的服务器收到了对新href的请求,但使用的是旧的data-method,即使我已将其从DELETE到POST(它仍然发送一个DELETE请求)。但是,如果我刷新页面,HTML与"new"HTML相同(随返回的JS发生变化),但它实际上发送了正确的请求类型。这就是这个问题令我困惑的
我在事件管理员编辑页面中有嵌套资源,但我只想允许管理员编辑现有资源的内容,而不是添加新的嵌套资源。我的代码看起来像这样:formdo|f|f.inputsdof.input:authorf.input:contentf.has_many:commentsdo|comment_form|comment_form.input:contentcomment_form.input:_destroy,as::boolean,required:false,label:'Remove'endendf.actionsend但它在输入下添加了“添加新评论”按钮。我怎样才能禁用它,并只为主窗体保留f.ac
我正在尝试消除使用Bootstrap3的Rails4元素中的glyphicon错误。我没有使用任何Bootstrapgem将其添加到Assets管道中。我手动将bootstrap.css和bootstrap.js添加到各自的app/assets目录下,分别添加到application.css和application.js什么的我现在在网络浏览器的控制台中看到以下内容:GEThttp://localhost:3000/fonts/glyphicons-halflings-regular.woff404(NotFound)localhost/:1GEThttp://localhost:30
我有这个:AccountSummary我想单击该链接,但在使用link_to时出现错误。我试过:bot.click(page.link_with(:href=>/menu_home/))bot.click(page.link_with(:class=>'top_level_active'))bot.click(page.link_with(:href=>/AccountSummary/))我得到的错误是:NoMethodError:nil:NilClass的未定义方法“[]” 最佳答案 那是一个javascript链接。Mechan
我目前正在尝试将ERB布局转换为HAML。这是我不断收到的错误:index.html.haml:18:syntaxerror,unexpected')'));}\n#{_hamlout.format_...这是HAML页面:.row-fluid.span6%h2TodoList.span6%h2{:style=>"text-align:right;"}document.write(today)%hr.divider.row-fluid.span6%h2.small_headNewTask=render:partial=>'layouts/form_errors',:locals=>{:
为现有模型生成单个文件(_form.html.erb)的命令是什么?在Rails3中工作。谢谢。 最佳答案 这听起来可能很傻,但请听我说完……当我想开始清洁时,我自己也做过几次这样的事情。以下是一个脚本,它将读取您的模式并生成必要的生成命令来重现它:require'rubygems'require'active_support/core_ext'schema=File.read('db/schema.rb')schema.scan(/create_table"(\w+)",.*?\n(.*?)\nend/m).eachdo|name