samuelcolvin的django-bootstrap3-datetimepicker在输入字段上单击时不显示日历 [英] samuelcolvin's django-bootstrap3-datetimepicker not showing calendar when clicked on input field

查看:119
本文介绍了samuelcolvin的django-bootstrap3-datetimepicker在输入字段上单击时不显示日历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 samuelcolvin的django-bootstrap3-datetimepicker ,其基于 Eonasdan的bootstrap-datetimepicker ,但从

I am trying to use samuelcolvin's django-bootstrap3-datetimepicker in which its based on Eonasdan's bootstrap-datetimepicker but forked from nkunihiko's django-bootstrap3-datetimepicker to show the calendar so the user can select the date and time and submit it. The issue I am having is that when I try to click on the field or on the right button with the calendar icon in it like in the demo website, it does not show me nothing.

我还必须将回购中的widgets.py添加到我的项目中,因为它给了我一个没有名为bootstrap3_datetime.widgets 的模块错误.

I also had to add widgets.py from the repo into my project since it was giving me a No module named bootstrap3_datetime.widgets error.

将感谢您的帮助

这就是我的models.py中的内容:

class Production(TimeStampedModel):

        #Some other code.....

        scheduled_date = models.DateTimeField(null=True, blank=True)
        fully_produced_date = models.DateTimeField(null=True, blank=True)

forms_schedule.py:

from producer.widgets import DateTimePicker

from django import forms

from .models import Production

class ScheduleForm(forms.ModelForm):

    class Meta:

        model = Production
        fields = ['scheduled_date', 'fully_produced_date']

    scheduled_date = forms.DateTimeField(required=False, widget=DateTimePicker(options={"format": "YYYY-MM-DD HH:mm", "pickSeconds": False}))

    # def clean_scheduled_date(self):
    #   scheduled_date = self.cleaned_data.get('scheduled_date')

        # return scheduled_date

    def clean_fully_produced_date(self):
        fully_produced_date = self.cleaned_data.get('fully_produced_date')

        return fully_produced_date

views.py

def episodeschedule(request):

    title = 'Podcast'
    title_align_center = True
    subtitle = 'Setup | Add Episode'
    subtitle_align_center = True
    form = ScheduleForm(request.POST or None)
    context = {
        "title": title,
        "subtitle": subtitle,
        "form": form
    }

    if form.is_valid():

        instance = form.save(commit=False)

        scheduled_date = form.cleaned_data.get("scheduled_date")
        fully_produced_date = form.cleaned_data.get("fully_produced_date")

        instance.scheduled_date = scheduled_date
        instance.fully_produced_date = fully_produced_date

        instance.user = request.user

        instance.save()

        return render(request, "forms_schedule.html", context)

    else:

            return render(request, "forms_schedule.html", context)

forms_schedule.html:

{% extends "base.html" %}
{% load crispy_forms_tags %}


{% block content %}

<div class="progress">
  <div class="progress-bar progress-bar-striped progress-bar-success active" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%">
    <span class="sr-only">100% Complete</span>
  </div>
</div>

<div class="panel panel-default box-shadow--16dp col-sm-6 col-sm-offset-3">
<div class="panel-body">

<div class='row'>
<div class='col-sm-12'>

{% if title %}
<h1 class='{% if title_align_center %}text-align-center{% endif %}'>{{ title }}<!-- : {{ get.clientsetup.company_name }} --></h1>
{% endif %}
{% if subtitle %}
<h3 class='{% if subtitle_align_center %}text-align-center{% endif %}'>{{ subtitle }}</h4>
{% endif %}

<h5>Schedule</h5>

<form method='POST' action=''>{% csrf_token %}
{{ form|crispy }}

<hr/>

<input class='btn btn-info box-shadow--6dp' type='submit' value='Save' />
<p>
<p>
<a class="btn btn-primary box-shadow--6dp" href="{% url 'dashboard' %}" role="button"><i class="fa fa-upload" aria-hidden="true"></i>&nbsp SCHEDULE EPISODE</a>

</form>
</div>
</div>

</div>
</div>

{% endblock %}

推荐答案

Settings.py

在已安装的应用中,添加"Bootstrap3_datetime"

Settings.py

In the Installed Apps Add 'Bootstrap3_datetime'

将以下行添加到HTML Head Tag

Add The following Lines into the HTML Head Tag

{%块标题%} {%load static%}

{% block header %} {% load static %}

   <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}} {%endblock%}

{{ form.media }} {% endblock %}

这篇关于samuelcolvin的django-bootstrap3-datetimepicker在输入字段上单击时不显示日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆