02.Django基础二之URL路由系统 (6)

那么其他的app中的urls.py中就不需要写app_name='应用名'了,看app01下urls.py的写法:

from django.conf.urls import url from django.contrib import admin from app01 import views urlpatterns = [ # url(r'^admin/', admin.site.urls), url(r'^index/', views.index,name='index'), ]

app02下urls.py的写法:

from django.conf.urls import url from django.contrib import admin from app02 import views urlpatterns = [ # url(r'^admin/', admin.site.urls), url(r'^index/', views.index,name='index'), ]

视图的写法:

#app01 def index(request): print(reverse('app01:index')) return HttpResponse('ok') #app02 def index(request): print(reverse('app02:index')) return HttpResponse('ok2')

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zyjppp.html