0

點擊,當我試圖使用其中samuelcolvin's django-bootstrap3-datetimepicker其基於Eonasdan's bootstrap-datetimepickernkunihiko's django-bootstrap3-datetimepicker叉,顯示日曆,以便用戶可以選擇的日期和時間,並提交。我遇到的問題是,當我嘗試點擊該字段或帶有日曆圖標的右側按鈕(如demo website)時,它不會顯示任何內容。samuelcolvin的Django的bootstrap3-的DateTimePicker不顯示日曆上輸入字段

我也不得不從回購加widgets.py到我的項目,因爲這是給我一個名爲bootstrap3_datetime.widgets 無模塊錯誤。

會感謝你的幫助

這是我在我的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 %} 

回答

0

Settings.py

在已安裝的應用程序添加 'Bootstrap3_datetime'

模板

添加以下行到HTML head標籤

{ %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}} {%末端嵌段%}

相關問題