re_path()

想要使用该函数,请导入如下模块:

from django.urls import include, re_path

函数参数如下:

re_path(route, view, kwargs=None, name=None)
  • The route argument should be a string or gettext_lazy() (see Translating URL patterns) that contains a regular expression compatible with Python’s re module. Strings typically use raw string syntax (r'') so that they can contain sequences like \d without the need to escape the backslash with another backslash. When a match is made, captured groups from the regular expression are passed to the view – as named arguments if the groups are named, and as positional arguments otherwise. The values are passed as strings, without any type conversion.
  • The view argument is a view function or the result of as_view() for class-based views. It can also be an django.urls.include().
  • The kwargs argument allows you to pass additional arguments to the view function or method. See Passing extra options to view functions for an example.
  • See Naming URL patterns for why the name argument is useful.
Naming URL patterns(name argument in re_path)

In order to perform URL reversing, you’ll need to use named URL patterns. The string used for the URL name can contain any characters you like. You are not restricted to valid Python names.

When naming URL patterns, choose names that are unlikely to clash with other applications’ choice of names. If you call your URL pattern comment and another application does the same thing, the URL that reverse() finds depends on whichever pattern is last in your project’s urlpatterns list.

Putting a prefix on your URL names, perhaps derived from the application name (such as myapp-comment instead of comment), decreases the chance of collision.

You can deliberately choose the same URL name as another application if you want to override a view. For example, a common use case is to override the LoginView. Parts of Django and most third-party apps assume that this view has a URL pattern with the name login. If you have a custom login view and give its URL the name login, reverse() will find your custom view as long as it’s in urlpatterns after django.contrib.auth.urls is included (if that’s included at all).

You may also use the same name for multiple URL patterns if they differ in their arguments. In addition to the URL name, reverse() matches the number of arguments and the names of the keyword arguments.(in addition to: 除了...)

include()

include(module, namespace=None)[source]

include(pattern_list)

include((pattern_list, app_namespace), namespace=None)

include function that takes a full Python import path to another URLconf module that should be “included” in this place.

Optionally, the application namespace and instance namespace where the entries will be included into can also be specified.

Usually, the application namespace should be specified by the included module. If an application namespace is set, the namespace argument can be used to set a different instance namespace.

include() also accepts as an argument either an iterable that returns URL patterns or a 2-tuple containing such iterable plus the names of the application namespaces.

Parameters:

  • module – URLconf module (or module name)
  • namespace (str) – Instance namespace for the URL entries being included
  • pattern_list – Iterable of path() and/or re_path() instances.
  • app_namespace (str) – Application namespace for the URL entries being included

See Including other URLconfs and URL namespaces and included URLconfs.

初学于此,鉴于 url匹配规则有点多,就先到这里吧。

转载请注明出处

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • xss基础实练(新手篇二)

    在知道反射型XSS,是通过URL地址传播的,那么就需要思考那些地方会让URL地址的参数在页面中显示;相信读者都用过一些网站的站内搜索,在站内搜索的位置往往会将搜...

    网e渗透安全部
  • Kali Linux渗透基础知识整理(二) 漏洞扫描 二(附送教程)

    这次继续上一篇文章,以后的每一篇文章底部都会推送一下教程或者一些实用工具哦,所以请大家认真看到底!

    网e渗透安全部
  • Go 语言基础入门教程 —— 第一个 Go 程序

    使用 Go 语言之前,首先要安装 Go。Go 为 Linux、Mac、Windows 等不同的平台分别提供了相应的安装包:https://golang.goog...

    学院君
  • 通过phpmyadmin GETshell

    general_log默认为关闭的,root权限开启后,general_log_file会保存所有的查询语句

    网e渗透安全部
  • phpmyadminroot账号获取webshell

    MysqlRoot账号通过phpMyAdmin获取webshell的思路,主要有下面几种方式,以第一二六八种方法较佳,其它可以根据实际情况来进行。

    网e渗透安全部
  • 谷歌hacker批量寻找可注入网站

    本次给大家发一些可以提取有注入点的网站的关键词,所利用的 也就是大家所熟悉的谷歌hack技术,下面是部分关键词,工具的话用一些关键词提取工具就好了。

    网e渗透安全部
  • 傀儡SQL的使用(快速寻找可注入网站)

    大家都听过SQL注入,但是对于新手来说,想要从网上众多网站中寻找到自己想要找到的目标并不是那么的容易,所以对于新手来说到底应该怎么更好的找到注入点呢...

    网e渗透安全部
  • 企业面试题: 如何获取浏览器中URL中查询字符串中的参数

    window.location 对象用于获得当前页面的地址 (URL),并把浏览器重定向到新的页面。

    舒克
  • php免杀webshell木马总结

    关于eval 于 assert 字符串变形 定义函数绕过 回调函数 回调函数变形 特殊字符干扰 数组 类 编码绕过 无字符特征马 PHP7.1后webshell...

    网e渗透安全部
  • Python urllib HTTP头注入漏洞

    Python的urllib库(在Python2中为urllib2,在Python3中为urllib)有一个HTTP协议下的协议流注入漏洞。如果攻击者可以控制Py...

    网e渗透安全部

扫码关注云+社区

领取腾讯云代金券