Converter 2: Convert ThinkPhp template to Django template, thinkphpdjango

Source: Internet
Author: User
Tags return tag

Converter 2: Convert ThinkPhp template to Django template, thinkphpdjango

I wrote a ThinkPhp template to Flask template the day before yesterday.

He was despised by his colleagues because he used Django. I used Flask to avoid him from continuing to use the power of Amway Django. I decided to write a Django template converter.

In order to reuse the code, I had to use inheritance. I split the original code into three sections and got three converters at once.

Class ConverterTemplateEncoding (object): separators = [('<', '>')] def _ init _ (self): self. match = {'opening': 0, 'closing': 0, 'extra ': 0, 'script': '', 'content':'', 'cache ': '', 'paramator': ()} def convert_tag (self, tag, extra =''): return tag... class ConverterThinkPhp2Jinja (ConverterTemplateEncoding): separators = [('{', '}'), ('_', '_'), ('<', '>'), ('<? ','?> ')] Class ConverterThinkPhp2Django (ConverterThinkPhp2Jinja): pass

What I didn't mean is that the Flask template is almost the same as the Django template, at least I didn't implement it. Haha.

If _ name _ = '_ main _': ConverterThinkPhp2Jinja (). convert_templates ('src', 'dst ')

 

Source code: converterV0.2.zip

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.