How to use jQuery datetimepicker plugin with Django -


i'm beginner django, working on first project. main functionality of site need use datetimepicker. since it's impossible use bootstrap (incompatible django 1.11) looks only(?) option handle one: jquery datetimepicker plugin.

i tried configure it, unfortunately see no result @ site. code:

forms.py

time_from = forms.datetimefield(widget=forms.datetimeinput(attrs={'class': 'datetimepicker'})) 

template - base.html

i put jquery , jqueryui static directory, add path them head section , {% load static %} between html tag , head. @ , of file have links datetimepicker.

<html> {% load static %}     <head>         <meta charset="utf-8">         <title>placyk</title>         <meta name="viewport" content="width-device-width, initial-scale=1">         <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-bvyiisifek1dgmjrakycuhahrg32omucww7on3rydg4va+pmstsz/k68vbdejh4u" crossorigin="anonymous">         <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rhyon1irsvxv4nd0jutlngaslcjuc7uwjduw9svrlvryoopp2bwygmgjqixwl/sp" crossorigin="anonymous">         <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-tc5iqib027qvyjsmfhjomalkfuwvxzxupncja7l2mcwnipg9mgcd8wgnicpd7txa" crossorigin="anonymous"></script>          <script type="text/javascript" src="{{ static_url }} /static/js/jquery-3.2.1.min.js"></script>         <script type="text/javascript" src="{{ static_url }} /static/js/jquery-ui-1.12.1.custom/jquery-ui.min.js"></script>     </head>     <body>         {% block content %}             <p>nothing</p>         {% endblock %}     </body>     <link rel="stylesheet" type="text/css" href="/static/datetimepicker-master/jquery.datetimepicker.css"/>     <script src="/static/datetimepicker-master/jquery.js"></script>     <script src="/static/datetimepicker-master/build/jquery.datetimepicker.full.min.js"></script> </html> 

template - specific view, extends base.html

<html>     {% extends 'base.html' %}     <script>         $(document).ready(function() {             $('.datetimepicker').datetimepicker();         });     </script>     {% block title %}<title>dodaj wizytę</title>{% endblock %}     {% block content %}             <form action="{% url 'add_visit' user.id %}" method='post'>         {{form}}         <input type='submit' value="submit">         {% csrf_token %}     </form>     {% if msg %}         <a href='/home_login'>strona główna</a>         {{msg}}     {% endif %}     {% endblock %} </html> 

views.py

class addvisitview(loginrequiredmixin, view):      def get(self, request, id):         user = user.objects.get(id=id)         form = addvisitform(user=user)         ctx = {'form': form, 'user': user}         return templateresponse(request, 'add_visit.html', ctx)      def post(self, request, id):         user = user.objects.get(id=id)         form = addvisitform(user, request.post)         if form.is_valid():             pground_id = form.cleaned_data['pground']             time_from = form.cleaned_data['time_from']             time_to = form.cleaned_data['time_to']             visit = visit.objects.create(pground_id = pground_id, time_from=time_from, time_to=time_to, who=user)             ctx = {'msg': 'visit added!', 'user': user}             return templateresponse(request, 'add_visit.html', ctx)         else:             ctx = {'form': form, 'user': user}             return templateresponse(request, 'add_visit.html', ctx) 

would kind , comment did wrong , how datetimepicker on site?

try using id selector instead of class selector when attaching datetimepicker

i.e.

$('#datetimepicker').datetimepicker() 

examples: http://xdsoft.net/jqplugins/datetimepicker/


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -