Python django.urls.re_path() Examples

The following are 9 code examples of django.urls.re_path(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.urls , or try the search function .
Example #1
Source File: django_micro.py    From django-micro with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def route(pattern, view_func=None, regex=False, *args, **kwargs):
    path_func = re_path if regex else path

    def decorator(view_func):
        if hasattr(view_func, 'as_view'):
            view_func = view_func.as_view()

        urlpatterns.append(path_func(pattern, view_func, *args, **kwargs))
        return view_func

    # allow use decorator directly
    # route('blog/', show_index)
    if view_func:
        return decorator(view_func)

    return decorator 
Example #2
Source File: v1.py    From onlinestudy with MIT License 6 votes vote down vote up
def get_urls(self):
        patterns = []

        for item in self._registry:
            model_class = item['model_class']
            handler_class = item['handler_class']
            prev = item['prev']
            app_label, model_name = model_class._meta.app_label, model_class._meta.model_name

            if prev:
                # patterns.append(re_path(r'^%s/%s/%s/list/$' % (app_label, model_name,prev), handler_class.changelist))
                # patterns.append(re_path(r'^%s/%s/%s/add/$' % (app_label, model_name,prev), handler_class.add_view))
                # patterns.append(re_path(r'^%s/%s/%s/change/(\d+)/$' % (app_label, model_name,prev), handler_class.change_view))
                # patterns.append(re_path(r'^%s/%s/%s/del/(\d+)/$' % (app_label, model_name,prev), handler_class.delete_view))
                patterns.append(
                    re_path(r'^%s/%s/%s/' % (app_label, model_name, prev), (handler_class.get_urls(), None, None)))
            else:
                # patterns.append(re_path(r'^%s/%s/list/$' % (app_label, model_name), handler_class.changelist))
                # patterns.append(re_path(r'^%s/%s/add/$' % (app_label, model_name), handler_class.add_view))
                # patterns.append(re_path(r'^%s/%s/change/(\d+)/$' % (app_label, model_name), handler_class.change_view))
                # patterns.append(re_path(r'^%s/%s/del/(\d+)/$' % (app_label, model_name), handler_class.delete_view))

                patterns.append(
                    re_path(r'^%s/%s/' % (app_label, model_name), (handler_class.get_urls(), None, None)))
        return patterns 
Example #3
Source File: route.py    From django-request-mapping with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self):
        self.urlpatterns: List[Union[path, re_path]] = list() 
Example #4
Source File: route.py    From django-request-mapping with GNU General Public License v3.0 5 votes vote down vote up
def update_urlpatterns(self, clazz, url_patterns_dict):
        for (path_type, full_value), action in url_patterns_dict.items():
            if path_type == 'path':
                self.urlpatterns.append(
                    path(full_value, clazz.as_django_request_mapping_view(action))
                )
            elif path_type == 're_path':
                self.urlpatterns.append(
                    re_path(full_value, clazz.as_django_request_mapping_view(action))
                )
            else:
                raise RuntimeError('not a valid path_type') 
Example #5
Source File: route.py    From django-request-mapping with GNU General Public License v3.0 5 votes vote down vote up
def _fix_path_value(full_value: str, path_type: str) -> str:
        # Remove redundant slants
        full_value = full_value.replace('//', '/', 1)
        if full_value.startswith('/'):
            full_value = full_value[1:]
        if path_type == 're_path':
            full_value = '^' + full_value
        return full_value 
Example #6
Source File: v1.py    From onlinestudy with MIT License 5 votes vote down vote up
def get_urls(self):
        """预留的重新自定义url钩子函数,主要是覆盖掉默认的url,并设置name别名"""

        patterns = [
            re_path(r'^list/$', self.wrapper(self.changelist), name=self.get_list_name),
            re_path(r'^add/$', self.wrapper(self.add_view), name=self.get_add_name),
            re_path(r'^change/(?P<pk>\d+)/$', self.wrapper(self.change_view), name=self.get_change_name),
            re_path(r'^del/(?P<pk>\d+)/$', self.wrapper(self.delete_view), name=self.get_del_name)

        ]
        patterns.extend(self.extra_url())
        return patterns 
Example #7
Source File: __init__.py    From polyaxon with Apache License 2.0 5 votes vote down vote up
def get_ui_urlpatterns(ui_urlpatterns):
    return [
        re_path(pattern, ensure_csrf_cookie(IndexView.as_view()), name="index",)
        for pattern in ui_urlpatterns
    ] 
Example #8
Source File: __init__.py    From polyaxon with Apache License 2.0 5 votes vote down vote up
def get_urlpatterns(app_patterns: List, ui_urlpatterns: List):
    if conf.get(ADMIN_VIEW_ENABLED):
        app_patterns += [re_path(r"^_admin/", admin.site.urls)]

    urlpatterns = app_patterns + [
        re_path(r"^healthz/?$", HealthView.as_view(), name="health_check"),
        re_path(r"^50x.html$", Handler50xView.as_view(), name="50x"),
        re_path(r"^permission.html$", Handler403View.as_view(), name="permission"),
        re_path(r"^404.html$", Handler404View.as_view(), name="404"),
    ]
    urlpatterns += get_ui_urlpatterns(ui_urlpatterns)

    return urlpatterns 
Example #9
Source File: distill.py    From django-distill with MIT License 5 votes vote down vote up
def distill_re_path(*a, **k):
        return _distill_url(re_path, *a, **k)