question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to modularize and customise pages?

See original GitHub issue

The recent changes to page creation with the release of 0.9.0 renders the example discussed in #50 unfeasible:

class MainPage(ui.page):
    def __init__(self):
        super().__init__('/', dark=True)
        with self:
            ui.label('Hi!')

MainPage()

I have tried adapting the code (using PageBuilder) in the simple example, but failed to get it running as before.

from nicegui import ui
from nicegui.globals import page_builders
from nicegui.page import Page
from nicegui.page_builder import PageBuilder


class MainPage(Page):
    def __init__(self):
        super().__init__(dark=True)

        ui.label('Hi!')


async def page_builder() -> Page:
    return MainPage()


def index_page():
    builder = PageBuilder(shared=False, function=page_builder)
    page_builders.setdefault('/', builder)


index_page()

ui.run()

results in

    raise RuntimeError('cannot find parent view, view stack is empty')
RuntimeError: cannot find parent view, view stack is empty

I have just recently migrated a great chunks of previously justpy code to the above inheritance approach including additional element/group classes (such as header, layout, pagecontainer, …) and am now seeking ways to make it work, again.

@falkoschindler: could you please guide me here, again? Thanks!

This issue is possibly related to #85.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
hroemercommented, Oct 1, 2022

@rodja many thanks for providing the discussion #99 and examples showing how to make use of ui.page. Apologies for my late reply, unfortunately I currently cannot devote much time on digging deeper here. I will get back to you once I wrapped my head around using this pattern.

1reaction
falkoschindlercommented, Sep 24, 2022

Another pattern might be to define the content in a class and do the routing in main.py:

class MainPage:
    def __init__(self):
        ui.label('Hi!')
@ui.page('/')
def main():
    MainPage()

Or define the page content in a function:

def main_page():
    ui.label('Hi!')
@ui.page('/')
def main():
    main_page()
Read more comments on GitHub >

github_iconTop Results From Across the Web

Using modular design to create an efficient & cost-effective ...
During design, you can limit the number of complete page designs required by identifying the components that will be reused across your website....
Read more >
Modular Pages - Grav Documentation
A Modular Page is a collection of pages stacked on top of each other to create a unified, single page. This lets you...
Read more >
Modular Front-End Development & Design - Toptal
Through a modular design approach, it is possible to both save time and streamline ... When you connect them together in the right...
Read more >
Modular Web Design - The Way Modern Websites Are Built
With modular web design, you can effectively cut the designer out of the process. You can assemble a live mockup of your landing...
Read more >
Modular Web Design: Building a Website that Grows with Your ...
Modular design has revolutionized the way websites are built. The process involves creating a flexible system of standalone, reusable components ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found