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不可访问配置设计   在java中使用json就像在javascript中一样   java如何屏蔽Android 4.0主密钥   java为什么clickable的预期条件不执行click()?   Azure事件中心:Kafka消费者在java中不轮询任何内容   javajaxb和enum实现接口   java如何在标记下添加ProgressBar和按钮   java如何为对象实现arrayList   使用多重匹配重载java构造方法重载   java使用for循环和if语句搜索帐户   java JPanel在JPanel中添加了顶部填充   IntelliJ将Java项目/模块转换为Maven项目/模块   java如何迭代arraylist中的arraylist   自定义类的java“找不到符号”错误