Python Forum
QuykHtml ( Library )
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QuykHtml ( Library )
#1
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 QuykHtml
Let 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
Reply
#2
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
Reply
#3
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?
Reply
#4
(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.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020