QuykHtml ( Library ) - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: General (https://python-forum.io/forum-1.html) +--- Forum: Code sharing (https://python-forum.io/forum-5.html) +--- Thread: QuykHtml ( Library ) (/thread-30721.html) |
QuykHtml ( Library ) - mwd1993 - Nov-02-2020 A python library that allows you to quickly and easily generate HTML templates and even create full-on websites. Check out the Github: https://github.com/mwd1993/QuykHtml Can be installed via Pip: https://pypi.org/project/QuykHtml/ pip install QuykHtmlLet me know any improvements I can make and how the usage is. Example: Hello World in 4 lines # Import the class from the library from QuykHtml import qhtml # Instantiate class q = qhtml() # Insert a modified p element into our main display q.display.insert(q.new('p').set_text('Hello World').set_id('text-id').style.set('font-size:24px;')) # Render the page q.display.render()More Examples RE: QuykHtml ( Library ) - mwd1993 - Jan-02-2021 There has been several updates since I've posted this. You can now use this library with flask. Test it easily on pythonanywhere.com Example 1: # A very simple Flask Hello World app for you to get started with... from QuykHtml import qhtml from flask import Flask q = qhtml() q.bootstrap.use(True) app = Flask(__name__) # always use " " as the outer string quote and ' ' inside if need on_click_code = "alert('You clicked the button!');" # Div containing a p element and a button with an on click event div = q.new('div').style.set('text-align:center;').insert([ q.new("p").style.font_size('42px').set_text("This works"), q.new('button').style.font_size('24px').set_text('click me').on_click(on_click_code) ]) # Div containing a p element with Greeting text in it div2 = q.new('div').style.set('background-color:gray;text-align:center;').insert([ q.new('p').style.set('font-size:32px;color:white;font-weight:bold;').set_text('Hello from QuykHtml and Flask!') ]) @app.route('/') def hello_world(): # Use .html method on a qhtml object to get it's HTML and serve it return div.html() + div2.html()Example 2: # A very simple Flask Hello World app for you to get started with... from QuykHtml import qhtml from flask import Flask q = qhtml() q.bootstrap.use(True) app = Flask(__name__) # always use " " as the outer string quote and ' ' inside if need on_click_code = "alert('You clicked the button!');" # Div containing a p element and a button with an on click event div = q.new('div').style.set('text-align:center;').insert([ q.new("p").style.font_size('42px').set_text("This works"), q.new('button').style.font_size('24px').set_text('click me').on_click(on_click_code) ]) # Div containing a p element with Greeting text in it div2 = q.new('div').style.set('background-color:gray;text-align:center;').insert([ q.new('p').style.set('font-size:32px;color:white;font-weight:bold;').set_text('Hello from QuykHtml and Flask!') ]) # Place objects in the display and render out the file to test.txt q.display.insert([div,div2]).render(output_file='test.txt', only_html=True) @app.route('/') def hello_world(): # Use file_read method to get the rendered HTML and serve it html = q.file_read('test.txt') return html RE: QuykHtml ( Library ) - horrorfodrasz - Jan-04-2021 Hi, I have tried your library. It is a nice job. I like it. I don't understand what are the advantages to generate HTML code in python instead of editing the code directly in HTML language? What do you think when would be preferable to use it? RE: QuykHtml ( Library ) - mwd1993 - Jan-05-2021 (Jan-04-2021, 04:59 PM)horrorfodrasz Wrote: Hi, I have tried your library. It is a nice job. I like it. Thanks! (Jan-04-2021, 04:59 PM)horrorfodrasz Wrote: I don't understand what are the advantages to generate HTML code in python instead of editing the code directly in HTML language? What do you think when would be preferable to use it? It really depends. I personally don't like doing stuff in raw HTML for several reasons: 1. Forgetting HTML syntax ( think on mouse hover commands, on click commands, auto complete for inputs, etc then having to use google ) 2. It takes longer to write the HTML out. (with QuykHtml and a nice IDE (pycharm?), allows for fast auto-completion) The benefits: 1. Quickly render/write html elements/files 2. Djangjo/Flask integration, you can easily use this library with the mentioned 3. It's in python! Think usage with projects that do: Data visualization, Web Scraping, Anything that uses HTML/JS or needs an interface 4. Write ajax requests to a server respectfully: client (quykhtml) -> server (not QuykHtml) - > client (quykhtml) 5. Easy GET/POST building with QuykHtml Basically, you can do html/js stuff fast. |