Django小部件DateTimePicker $未定义

时间:2015-07-27 16:01:16

标签: python django datetimepicker

我想在我的模型中添加一个DateTimePicker小部件,但是我有一些模板问题,它不起作用而且不显示日历。 我认为这是块的问题和使用widget生成的内容。也许我可以关闭此功能,或手动编辑此部分?

在控制台中我有错误:

 Movie[] inMovies = new Movie[count];
            for (int i = count - 1; i >= 0; i--) {

                File file = new File(lv1List.get(i));
                if (file.exists()) {
                    try {
                        inMovies[counter] = MovieCreator.build(file.getAbsolutePath());
                        counter++;
                    } catch (Exception e) {
                        Log.d("mp4parse", e.getMessage());
                    }
                }

            }
            List<Track> videoTracks = new LinkedList<Track>();
            List<Track> audioTracks = new LinkedList<Track>();
for (Movie m : inMovies) {
                    for (Track t : m.getTracks()) {

                        if (t.getHandler().equals("vide")) {
                            videoTracks.add(t);
                        }
                    }
                }
                try {
                    MP3TrackImpl aacTrack = new MP3TrackImpl(new FileDataSourceImpl(audiopath));
                    CroppedTrack aacTrackShort = new CroppedTrack(aacTrack, 1, aacTrack.getSamples().size());
                    audioTracks.add(aacTrackShort);
                } catch (Exception e) {
                    e.printStackTrace();
                }
 Movie result = new Movie();

            try {
                if (audioTracks.size() > 0) {
                    result.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()])));
                }
                if (videoTracks.size() > 0) {
                    result.addTrack(new AppendTrack(videoTracks.toArray(new Track[videoTracks.size()])));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            try {
                Container out = new DefaultMp4Builder().build(result);
                String filename = Environment.getExternalStorageDirectory().getAbsolutePath() + "/MERGEDoutput" + Long.toString(System.currentTimeMillis()) + ".mp4";
                FileOutputStream fos = new FileOutputStream(new File(filename));

                out.writeContainer(fos.getChannel());
                fos.close();
            } catch (Exception e) {

            }

由小部件(浏览器)生成的模板脚本:

Uncaught ReferenceError: $ is not defined

Form.py

<p><label for="id_event_date">Event date:</label> 
   <div id="id_event_date" class="input-group date">
       <input class="form-control" id="id_event_date" name="event_date" type="text" value="2015-07-28 03:39:46" />
       <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
       <span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
   </div>

   <script type="text/javascript">
       $("#id_event_date").datetimepicker({
           autoclose: true,
           language: 'ru',
           format: 'yyyy-mm-dd    hh:ii:ss'
       }).find('input').addClass("form-control");
   </script>

   <input id="initial-id_event_date" name="initial-event_date" type="hidden" value="2015-07-28 03:39:46" /></p>

我的模板(代码):

from django import forms
from .models import Event 
from datetimewidget.widgets import DateTimeWidget


class EventConstr(forms.ModelForm):
    class Meta:
        model = Event
        fields = ['title', 'event_date']

        widgets = {
            'event_date': DateTimeWidget(attrs={'class': "form-control"}, usel10n = True, bootstrap_version=3)
        }

如果我能给你更多信息,请问我!

1 个答案:

答案 0 :(得分:0)

$ is not defined表示您尚未加载jQuery。

因此,您需要在基本模板或类似内容中加载它;

<script type="text/javascript" src="//code.jquery.com/jquery-1.11.3.min.js"></script>