Javascript 如何将日期/日历小部件添加到django表单?

Javascript 如何将日期/日历小部件添加到django表单?,javascript,django,django-forms,django-templates,django-views,Javascript,Django,Django Forms,Django Templates,Django Views,我试着跟着这些,但没有成功。这个小部件没有加载到表单中,当可以从链接访问它时,js文件在控制台中给出404错误。我用脆的形式来呈现我的形式 forms.py DateInput = partial(forms.DateInput, {'class': 'datepicker'}) # patient Form class PatientForm(ModelForm): birth_date = forms.DateField(label='Bir

我试着跟着这些,但没有成功。这个小部件没有加载到表单中,当可以从链接访问它时,js文件在控制台中给出404错误。我用脆的形式来呈现我的形式

forms.py

       DateInput = partial(forms.DateInput, {'class': 'datepicker'})

    # patient Form
    class PatientForm(ModelForm):

        birth_date = forms.DateField(label='Birth Date',widget=DateInput())
        class Meta:
            model = Patient
            exclude = ['user',]
模板

           <h2>Add Patient</h2>
            <form method="POST" action="{% url 'patients:patient_create' %}">

                {% csrf_token %}
                 {{ form|crispy }}
                <button type="submit" class="btn btn-primary" >Add Patients</button>
                <p></p>
            </form>
</div>
    {% endblock %}

    <script>
    $(document).ready(function() {
        $('.datepicker').datepicker();
    });
    </script>
Not Found: /patients/”https://code.jquery.com/jquery-1.12.4.js”
Not Found: /patients/”https://code.jquery.com/ui/1.12.1/jquery-ui.js”
[18/Jul/2019 15:29:09] "GET /patients/%E2%80%9Dhttps://code.jquery.com/jquery-1.12.4.js%E2%80%9D HTTP/1.1" 404 6742
[18/Jul/2019 15:29:09] "GET /patients/%E2%80%9Dhttps://code.jquery.com/ui/1.12.1/jquery-ui.js%E2%80%9D HTTP/1.1" 404 6760
Not Found: /patients/”https://code.jquery.com/jquery-1.12.4.js”
[18/Jul/2019 15:29:10] "GET /patients/%E2%80%9Dhttps://code.jquery.com/jquery-1.12.4.js%E2%80%9D HTTP/1.1" 404 6742
Not Found: /patients/”https://code.jquery.com/ui/1.12.1/jquery-ui.js”
[18/Jul/2019 15:29:10] "GET /patients/%E2%80%9Dhttps://code.jquery.com/ui/1.12.1/jquery-ui.js%E2%80%9D HTTP/1.1" 404 6760
Not Found: /favicon.ico
在我的代码中,有许多jquery版本可能会导致问题。我想要一个比jquery ui更友好的小部件,那么有没有其他方法可以用来添加与jquery ui相同方式的小部件?

在表单中。py:

class DateInput(forms.DateInput):
     input_type = 'date'

class PatientForm(ModelForm):


        class Meta:
            model = Patient
            exclude = ['user',]
            widgets = {
                'birth_date':DateInput,
               }

试试这个

问题是现代浏览器如果不将
类型
改为
日期

这是为我解决这个问题的方法

DateInput = partial(forms.DateInput, {'class': 'datepicker','type': 'date'})
# patient Form
class PatientForm(ModelForm):

    birth_date = forms.DateField(label='Birth Date',widget=DateInput())
    class Meta:
        model = Patient
        exclude = ['user',]

现在我得到了这个错误'functools.partial'对象没有属性'is_hidden'您是否删除了这一行
DateInput=partial(forms.DateInput,{'class':'datepicker'})
如果不尝试删除它,那么我如何才能在类中引用
日期输入
?@ammarady我不明白您想说的内容
日期输入
在您要我删除的行中定义。
DateInput = partial(forms.DateInput, {'class': 'datepicker','type': 'date'})
# patient Form
class PatientForm(ModelForm):

    birth_date = forms.DateField(label='Birth Date',widget=DateInput())
    class Meta:
        model = Patient
        exclude = ['user',]