美文网首页
Django学习(1)--创建第一个网站

Django学习(1)--创建第一个网站

作者: jack_hw | 来源:发表于2018-11-17 18:44 被阅读0次

对于https://docs.djangoproject.com/zh-hans/2.1/intro/tutorial01/  实例中poll的理解

在poll中定义的view.py是后台直出页面:

from django.http import HttpResponse

def index(request):

    return HttpResponse("Hello, world. You're at the polls index.")

urls.py:

polls/urls.py

from django.urls import path

from . import views

urlpatterns = [

    path('', views.index, name='index'),

path('huwei',views.index,name='huwei2'),

]

第一个参数指定的是访问的url。最后一个name是什么还不知道;测试过访问 http://localhost:8000/polls/ 和http://localhost:8000/polls/huwei是正常的,访问huwei2是不正常的

mysite里的urls.py:

from django.contrib import admin

from django.urls import include,path

urlpatterns = [

    path('polls/', include('polls.urls')),

    path('admin/', admin.site.urls),

]

其中path函数,第一个指定了是url,第二个叫做view,但是查看include的返回值是一个三元组:(urlconf_module, app_name, namespace)

相关文章

网友评论

      本文标题:Django学习(1)--创建第一个网站

      本文链接:https://www.haomeiwen.com/subject/xjvpfqtx.html