django 中的 url.py,^ 有什么作用? [英] url.py in django, what does ^ do?
本文介绍了django 中的 url.py,^ 有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我刚开始学习 django,我目前正在处理 urls.py 文件.我想知道是否有人可以向我解释网址开头的^"是什么?如果我说的没有意义,我也发布了一些代码.
So ive just started learning django and im currently messing around with the urls.py file. I was wondering if someone could explain to me what the "^" at the start of the url does? I posted some code too if what I said doesnt make sense.
url(r'^$', post_timeline),
推荐答案
在 urls.py,
^ means the start of the URL string and $ is the end of the URL.
例如:
from django.conf.urls import url, patterns
urlpatterns = [
url(r'^some_base_path/', include('your_app.urls', namespace='your_app')),
]
在你的应用的 urls.py 中:
And in urls.py of your app :
urlpatterns = patterns(
url(r'^some_url$', your_app.some_view),
)
在第二个 URL 中,r'^some_url$' 表示从 some_url 开始,$ 表示该 URL 到此结束.不能再添加其他 URL 字符串.
Here in the second URL, r'^some_url$' means start at some_url and $ means that the URL ends here.NO further URL string can be added to it.
这篇关于django 中的 url.py,^ 有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文