在这里试用教程
设置.py
DRAGON_URL = 'http://localhost:9999/'
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'notifications.context_processors.dragon_url',
)
沼泽龙设置
SWAMP_DRAGON_CONNECTION = ('swampdragon.connections.sockjs_connection.DjangoSubscriberConnection', '/data')
context_processors.py
from django.conf import settings
def dragon_url(request):
return {'DRAGON_URL': settings.DRAGON_URL}
主页.html
{% load staticfiles %}
{% load swampdragon_tags %}
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<h1>Notifications demo</h1>
<!-- This is our list of notifications -->
<ul id="notifications">
{% for notification in object_list %}
<li>{{ notification.message }}</li>
{% endfor %}
</ul>
<!-- SwampDragon -->
{% swampdragon_settings %}
<script type="text/javascript" src="{% static 'swampdragon/js/dist/swampdragon.js' %}"></script>
<script type="text/javascript" src="{% static 'swampdragon/js/vendor/sockjs-0.3.4.min.js' %}"></script>
<script type="text/javascript" src="{% static 'swampdragon/js/legacy/swampdragon-vanilla.js' %}"></script>
<script type="text/javascript" src="{% static 'notifications.js' %}"></script>
<script type="text/javascript" src="{% static 'swampdragon/js/dist/datamapper.js' %}"></script>
<script type="text/javascript" src="{{ DRAGON_URL }}settings.js"></script>
<!-- notifications -->
<script type="text/javascript" src="{% static 'notifications.js' %}"></script>
</body>
</html>
控制台中的错误
ReferenceError: SwampDragon is not defined
var sdInstance = new SwampDragon(options);
还尝试在控制台中显示设置
<script>
console.log(window.swampdragon_settings);
</script>
我明白了
endpoint "/data"
不知道出了什么问题。如果需要更多信息,请告诉我。
如果需要点冻结
backports.ssl-match-hostname==3.4.0.2
certifi==2015.4.28
Django==1.7
django-filter==0.10.0
djangorestframework==3.1.3
Markdown==2.6.2
python-dateutil==2.4.2
redis==2.10.3
six==1.9.0
sockjs-tornado==1.0.1
SwampDragon==0.4.2.2
tornado==4.2
tornado-redis==2.4.18
wheel==0.24.0