转换你的角度索引.html文件到Django模板语法

ng2django的Python项目详细描述


ng2django公司

PyPIPyPI - License

这是一个简单的Python工具,可以将Angular2+构建的HTML文件转换为Django模板语言。这样,静态文件就可以提供给与Django项目一起提供的Agnular应用程序。在

剧本主要做两件事:

  • {% load static %}标记添加到文件顶部
  • linkscript标记的hrefsrc属性的值更改为{% static "<path-to-the-file>" %}

依赖关系

脚本使用Beutifulsoup4。您可以通过运行pip install -r requirements.txt来安装它。在

安装

只需运行$ pip install ng2django

使用

构建你的Angular应用程序并将文件放入<Django-project-root>/<app>/static/<optional-subdirectory>/。在

脚本接受两个位置参数:

  • source:要转换的HTML文件的路径。在
  • dest:保存Django模板文件的位置。在

然后你就可以跑了

$ ng2django <Django-project-root>/<app>/static/index.html <Django-project-root>/<app>/templates/index.html

如果您将文件直接存储在Django应用程序的static和{}目录中(不推荐),或者

$ ng2django <Django-project-root>/<app>/static/<optional-subdirectory>/index.html <Django-project-root>/<app>/templates/<optional-subdirectory>/index.html -s <optional-subdirectory>

如果您正在使用这些路径的某个子目录。在

可选参数

ShortLongDescription
-s ^{}--subdir ^{}Include the subpath under ^{} where your static files are stored.
-css ^{}--cssdir ^{}Include the subpath under ^{} where your static CSS files are stored.
-js ^{}--jsdir ^{}Include the subpath under ^{} where your static JS files are stored.
-img ^{}--imgdir ^{}Include the subpath under ^{} where your static IMAGE files are stored.
-n--nodeleteDo not delete the source file after converting.
-p--prettyCreate a dest file that is more human readable.

建议的设置和使用方法

在角度项目中,打开package.json文件。在scripts下,将build更改为

ng build --prod --output-path <Your-django-project-root>/<Django-App>/static/ng。在

script下添加一个postbuild键,并将值设置为

ng2django <Your-django-project-root>/<Django-App>/static/ng/index.html <Your-django-project-root>/<Django-App>/templates/ng/index.html -s ng。在

或者,如果在静态参数中的单独目录中有css/js/images:-css css-js-img img ng2django <Your-django-project-root>/<Django-App>/static/ng/index.html <Your-django-project-root>/<Django-App>/templates/ng/index.html -s ng -css css -js js -img img。在

运行npm run build,你的角度JS和CSS文件将被保存到Django应用程序的静态目录中。然后,这个脚本将运行并转换HTML文件并将其保存在Django应用程序的templates目录中。在

贡献

欢迎投稿-提交问题/拉请求。在

推送到PyPi

使用这些命令在PyPi上发布

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

推荐PyPI第三方库


热门话题
这个链表分区算法是如何工作的?   java最小化Spring启动时间   Java8不兼容类型   java优缺点:Jetbrains IntelliJ/Sublime Text   java在一个JTable单元格中包含两行或更多行?   使用Java将HTTP请求GET/POST发送到表单?   java如何在SpringMVC中使用重定向在jsp上显示验证消息   绑定动态列表时出现java问题   安卓在Java和使用obj之间的性能。getXY()和对象o=obj。getXY()   java如何获取Ehcache中的对象数?   java如何实现ArrayList以将“Room”对象添加到“House”对象列表中?   java IntelliJ无法解析符号“数组”   java为什么我不能按我需要的方式使用TypeToken?   java sql server数据插入错误   java解析代数表达式以查找变量   JavaSpring,如何使用WebSocket向连接的客户端广播消息?   java解析xml获取XmlPullParserException   java在安装Android应用程序时创建文件   在java中现有的PDF页面上添加条形码128