django url的注意

1.通常我们可以项目下url.py中,使用include()关联到模块中的url,然后在子app中的url.py 进行修改。

2.我们也可以在项目下的url.py 直接编写

3.相同url开头的url的坑:

from django.conf.urls import url
from . import views
urlpatterns=[
    url(r"^index/$",views.index),
    # url(r"^say/$",views.say,name='say'),
    url(r"^say",views.say,name='say'),
    url(r"^sayhello",views.sayhello,name="sayhello"),
    url(r"^add2/(\d+)/(\d+)/$",views.add2,name='add2')
]

views.py

def say(request):
    return HttpResponse("hello")
def sayhello(request):
    return HttpResponse("sayhello")

猜你喜欢

转载自blog.csdn.net/liming066/article/details/81975689