jQuery datepicker Django的 [英] Jquery datepicker django

查看:75
本文介绍了jQuery datepicker Django的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试让jQuery datepicker在django上工作,我一直在研究 显示日期选择器,但我没有运气.

I've been trying to get the jquery datepicker to work on django, I've looked at Show datepicker but I've had no luck.

我的日期定义为

    date = models.DateTimeField('Published Date')

我在表单中的日期设置为:

My date in the form is setup as:

class UploadForm(forms.ModelForm):
    class Meta:
        model = Archive
        widgets = {
            'date': forms.DateInput(attrs={'class': 'datepicker'}),
               }

在我的upload.html

In My upload.html

{% extends 'budget/base_form_views.html' %}
<script>
  $(function() {
    $('.datepicker').datepicker({
    changeMonth:true,
    changeYear: true,
    yearRange: 1900:2100,})
  });
</script>
//generated form//

upload.html扩展了base_form.html,所有脚本均已加载在那里

The upload.html extends base_form.html and all the scripts are loaded there

<head>  
    <script type="text/javascript" src="{% static 'budget/js/jquery-1.10.2.js' %}"></script>
    <script type="text/javascript" src="{% static 'budget/js/jquery-ui-1.10.4.custom.js' %}"></script>
    <script type="text/javascript" src="{% static 'budget/js/bootstrap.js' %}"></script>
    <link rel="stylesheet" type="text/css" href="{% static 'budget/css/jquery-ui.css' %}" />
    <link rel="stylesheet" type="text/css" href="{% static 'budget/css/bootstrap.css' %}" />

</head> 

当我单击日期文本字段时,什么都没有发生.在firefox控制台中,所有脚本和CSS的加载都没有错误.

Nothing happends when I click on the date text field, In the firefox console, all scripts and css's get load with no errors.

我正在使用Django 1.6.5.

I'm using Django 1.6.5.

有什么我想念的吗?

忘记将上传视图"添加到帖子中.

edit: forgot to add Upload View to post.

class UploadView(FormView):
    template_name = "budget/upload.html"
    form_class = UploadForm
    success_url = reverse_lazy('view')

推荐答案

好,我终于设法使其正常工作.

Ok, I finally managed to get it to work.

UploadForm

The UploadForm

class UploadForm(forms.ModelForm):
    date = forms.DateField(widget=forms.DateInput(attrs={'class': 'datepicker'}))
    ....

upload.html文件包含

The upload.html file contains

<script>
    $(document).ready(function() {
        $('.datepicker').datepicker();
    });
</script>

仅提醒您,upload.html扩展了我的base.html,其中包含了所有jquery脚本

Just a reminder that upload.html extends my base.html which houses all the jquery scripts

这篇关于jQuery datepicker Django的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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