Plain is headed towards 1.0! Subscribe for development updates →

 1from plain.runtime import settings
 2from plain.urls import include, path
 3from plain.utils.module_loading import import_string
 4
 5from .registry import registry
 6
 7default_namespace = "pages"
 8
 9
10def get_page_urls():
11    """
12    Generate a list of real urls based on the files that exist.
13    This way, you get a concrete url reversingerror if you try
14    to refer to a page/url that isn't going to work.
15    """
16    paths = []
17
18    view_class = import_string(settings.PAGES_VIEW_CLASS)
19
20    for url_path in registry.url_paths():
21        if url_path == "":
22            # The root index is a special case and should be
23            # referred to as pages:index
24            url = ""
25            name = "index"
26        else:
27            url = url_path + "/"
28            name = url_path
29
30        paths.append(
31            path(
32                url,
33                view_class,
34                name=name,
35                kwargs={"url_path": url_path},
36            )
37        )
38
39    return paths
40
41
42urlpatterns = [
43    path("", include(get_page_urls())),
44]