django的可重用应用程序很好地连接了客户端和服务器端。

django-xross的Python项目详细描述


https://github.com/idlesign/django-xross

https://img.shields.io/pypi/v/django-xross.svghttps://img.shields.io/pypi/dm/django-xross.svghttps://img.shields.io/pypi/l/django-xross.svghttps://img.shields.io/coveralls/idlesign/django-xross/master.svghttps://img.shields.io/travis/idlesign/django-xross/master.svghttps://landscape.io/github/idlesign/django-xross/master/landscape.svg?style=flat

说明

django的可重用应用程序很好地连接了客户端和服务器端。

在HTML中使用一些声明性技术简化服务器和客户端的交互, 在你的观点中有几个xross函数。

在您的视图中的某个位置。py

fromdjango.shortcutsimportrenderfromxross.toolboximportxross_view,xross_listener# That's all we need from xross.deflist_news(request):"""This function will be used by xross to load news using AJAX."""news=...# Here we fetch some news from DB.returnrender(request,'mytemplates/sub_news.html',{'news':news})@xross_view(list_news)# Decorate your view - instruct xross to use `list_news` when needed.defindex_page(request):"""This is our view to streamline."""xross_listener()# xross will handle AJAX calls from that moment.returnrender(request,'mytemplates/index.html')

现在转到您的mytemplates/index.html

<!DOCTYPE html><html><head><!-- xross depends on jQuery. Include it. --><scriptsrc="http://yandex.st/jquery/2.1.1/jquery.min.js"></script><!-- Now xross itself. --><scriptsrc="{{ STATIC_URL }}js/xross/xross.min.js"></script><scripttype="text/javascript">xross.automate();// Instruct xross to watch for page elements with `xross` class.
</script></head><body><divid="list_news"class="xross"><!--
            Contents of this div will be replaced with news from Django's `list_news()`
            automatically on page load.

            That's the default of xross, but it knows some other nice little tricks.
            Read the docs.
         --></div></body></html>

最后mytemplates/sub_news.html(没什么特别的):

{% for item in news %}
    <div><div>{{ item.title }}</div><div>{{ item.text }}</div></div>
{% endfor %}

不是全部,不是全部。阅读文档!

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
用Java将dpi元数据写入jpeg图像   文件为什么Java会自动解码URI编码的文件名中的%2F?   java多动态时间事件侦听器   java中如何递归查找不同级别的属性值   java Apache Spark MySQL JavaRDD。foreachPartition为什么我得到ClassNotFoundException   Java中的循环变量文件名   java如何参数化调用JNA库的C库名称和路径?   swing如何使gif在Java中运行一次并停止?   Big Sur上的MacOS应用程序,具有java子进程和可访问性API权限   在page类中定义的java Webelement在测试类中不可访问   如何使用java if else从JSON文件中删除重复的元素?   java Android studio dalvik vm找不到类   java在数组中正确使用协方差