用于django项目的与bootstrap4兼容的datetimepicker。

django-bootstrap4-datetimepicker的Python项目详细描述


此包使用由以下项目提供的引导v3 DateTimePicker小部件版本2:
https://github.com/Eonasdan/bootstrap-datetimepicker
可在此处找到日期的正确格式选项:
http://momentjs.com/docs/

它只适用于bootstrap3。如果您在 Django项目,看看这个: https://github.com/zokis/django-bootstrap-datetimepicker

安装

  • 运行pip install django-bootstrap3-datetimepicker
  • 'bootstrap3_datetime'添加到INSTALLED_APPS

示例

forms.py

from bootstrap3_datetime.widgets import DateTimePicker
from django import forms

class ToDoForm(forms.Form):
    todo = forms.CharField(
        widget=forms.TextInput(attrs={"class": "form-control"}))
    date = forms.DateField(
        widget=DateTimePicker(options={"format": "YYYY-MM-DD",
                                       "pickTime": False}))
    reminder = forms.DateTimeField(
        required=False,
        widget=DateTimePicker(options={"format": "YYYY-MM-DD HH:mm",
                                       "pickSeconds": False}))

options将传递给javascript datetimepicker 实例。可用的options解释如下 文档:

您不需要设置language选项,因为它将被设置 线程的当前语言。

template.html

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet"
              href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.css">
        <link rel="stylesheet"
              href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.css">
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.js">
        </script>
        <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.js">
        </script>
        {{ form.media }}
    </head>
    <body>
        <form method="post" role="form">
            {% for field in form.visible_fields %}
            <div id="div_{{ field.html_name }}"
                 class="form-group{% if field.errors %} has-error{% endif %}">
                {{ field.label_tag }}
                {{ field }}
                <div class="text-muted pull-right">
                    <small>{{ field.help_text }}</small>
                </div>
                <div class="help-block">
                    {{ field.errors }}
                </div>
            </div>
            {% endfor %}
            {% for hidden in form.hidden_fields %}
                {{ hidden }}
            {% endfor %}
            {% csrf_token %}
            <div class="form-group">
                <input type="submit" value="Submit" class="btn btn-primary" />
            </div>
        </form>
    </body>
</html>

bootstrap3和jquery必须与 {{ form.media }}

发行说明

2.3版

  • 将bootstrap-datetimepicker.js更新到3.0版

2.2.3版

  • 将bootstrap-datetimepicker.js更新为2.1.30版

2.2.3版

  • 将bootstrap-datetimepicker.js更新为2.1.30版

2.0.0版

  • 包括bootstrap-datetimepicker.js版本2.1.11和moment.js
  • 由于使用moment.js,格式字符串已更改

要求

  • python=2.4
  • django>;=1.3
  • 引导程序=3.0

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java关闭到DB的连接不会关闭所有连接   java如何跟踪eclipse中编译错误的错误?   java设计/实现。。。最有可能使用AJAX   java无法从SharedReference获取数据   在java中,用|将印地语段落串成   java以编程方式在单击时创建微调器工作   java对如何完成新程序的困惑?   java停止httpConnection blackberry超时   java为什么继承的静态变量可以被子类的非静态方法访问?   java Spring安全性通过控制器进行身份验证   java类继承和泛型类型   创建票证服务时CAS重定向上的java错误   使用java的sockets对等应用程序