关于django中的reverse()函数的一些理解

时间:2022-03-24 19:32:06

参考了:http://www.mamicode.com/info-detail-1104211.html

  urls.py

urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^ueditor/', include(DjangoUeditor_urls)),
url(r'^$',news_views.index,name='index'),
url(r'^column/(?P<column_slug>[^/]+)/$',news_views.column_detail,name='column'),
url(r'^news/(?P<article_slug>[^/]+)/$',news_views.article_detail,name='article1'),
]





models.py
def get_absolute_url(self):
return reverse('article1', args=(self.slug,)) #reverse的第一个参数是urls.pyurl中的name

比如这里的name='article1'