Package: django-templater
Django TemplaterCreate Django templates from HTML filesDjango TemplaterDescriptionInstallationHow does it work?Convert entire projectConvert assets URLQuick StartConvert entire projectConvert assets URLAdvanced UsageConvert entire projectStatic FilesDownloading Remote FilesRemote templatesConvert assets URLStatic FilesChanging output directoryDownloading Remote FilesContributingLicenseDescriptionDjango Templateris a command line tool that will help you to convert your HTML templates to Django templates.Installation>pipinstalldjango-templaterHow does it work?Convert entire projectThis working mode will convert all HTML files in the specified directory to Django templates and split them into master page and child pagesTo create a new Django project, you need to specify the main block name. The main block name is the name of the block that will be used in the base HTML file. The main block name is required.For example:Base HTML file<!-- ./templates/base.html --><htmllang="en"><head><title>My Website</title></head><body><divclass="header"id="main_block"><h1>My Website</h1><p>Welcome to my website</p></div></body></html>Home HTML file<!-- ./templates/home.html --><htmllang="en"><head><title>My Website</title></head><body><divclass="header"id="main_block"><h1>User Home</h1><p>Welcome to the user home page</p><imgsrc="assets/images/logo.png"alt="Logo"></div></body></html>On the above example, the main block name ismain_block. So, when you create a new Django project, the main block name will be used as the name of the block in the base HTML file.Convert assets URLThis working mode will convert all assets URL in the specified directory to Django static URL.For example:Home HTML file<!-- ./templates/home.html --><htmllang="en"><head><title>My Website</title></head><body><divclass="header"id="main_block"><h1>User Home</h1><p>Welcome to the user home page</p><imgsrc="assets/images/logo.png"alt="Logo"></div></body></html>On the above example, the assets URL isassets/images/logo.png. So, when you create a new Django project, the assets URL will be converted to Django static URL:<htmllang="en"><head><title>My Website</title></head><body><divclass="header"id="main_block"><h1>User Home</h1><p>Welcome to the user home page</p><imgsrc="{% static 'assets/images/logo.png' %}"alt="Logo"></div></body></html>Quick StartConvert entire projectLet say you have an HTML templates in./templatesdirectory.Django master page will be:./templates/base.htmlDjango home page will be:./templates/home.html,./templates/users.htmlor./templates/home/setting.htmlHTML main block we want to use is:main_blockWe want to create a Django project in./myprojectdirectory and we want to use./templatesdirectory as Django templates directory, and the output will be in./myprojectdirectory.>dt-bmain_block./templates/base.html-o./myproject./templates/*This command will generate the following files:<!-- ./output/base.html --><html lang="en"><head><title>My Website</title></head><body><div class="header" id="main_block">{%blockmain_block%}{%endblock%}</div></body></html><!-- ./output/home.html -->{%extends"base.html"%}{%loadstatic%}{%blockmain_block%}<h1>User Home</h1><p>Welcome to the user home page</p><img src="{%static'assets/images/logo.png'%}" alt="Logo">{%endblock%}Convert assets URLLet say you have a HTML template called./templates/home.htmland you want to convert all assets URL in this file to Django static URL.>dtttemplates/home.htmlNote: If you don't set the output directory, the result will be printed to the console.Advanced UsageConvert entire projectStatic FilesBy default this project will copy all static files to the Django static directory. The static directory we'll bestaticin your output directory. You can change the static directory by using-sor--staticoption.>dt-bmain_block-m./templates/base.html-o./myproject-sassets./templates/*Downloading Remote FilesYou can also download remote assets automatically. If your HTML files contains remote assets, this project will download the remote assets and copy them to the static directory.>dt-bmain_block-m./templates/base.html-D-o./myproject./templates/*Remote templatesYou can also use remote templates. This project will download the remote templates and copy them to the templates directory.>dt-bmain_block-mhttps://example.com/base.html-o./myproject./templates/*Convert assets URLStatic FilesBy default this project will copy all static files to the Django static directory. The static directory we'll bestaticin your output directory. You can change the static directory by using-sor--staticoption.>dtt-sassetstemplates/home.htmlChanging output directoryYou can change the output directory by using-oor--outputoption.>dtt-o./myprojecttemplates/home.htmlNote: If you don't set the output directory, assets output will be relative to it.Downloading Remote FilesYou can also download remote assets automatically. If your HTML files contains remote assets, this project will download the remote assets and copy them to the static directory.>dtt-Dtemplates/home.htmlContributingContributions are welcome! Please feel free to submit a Pull Request.LicenseThis project is licensed under the terms of the MIT license.