第一种方式来访问第一个页面(不常用)
1.blog/views.py
from django.http import HttpResponse
def index(request):
return HttpResponse('hello world')
2.myblog/urls.py
import blog.views as bv
urlpatterns = [
path('admin/', admin.site.urls),
path('index/', bv.index),
path('zhang/', bv.zhang),
]
3.直接url访问
第二种方式来访问第一个页面(常用)
1.在blog/views.py
from django.http import HttpResponse
def index(request):
return HttpResponse('你好,世界')
2.myblog/urls
from django.urls import path,include
urlpatterns = [
path('admin/', admin.site.urls),
path('blog/', include('blog.urls')), *index主目录*
]
3.在blog/里创建urls.py
from django.urls import path
from . import views
urlpatterns = [
path('/index, views.index),*index子目录*
]
4.访问127.0.0.1:8000/blog