Django基础

1.配置路由 :     

在自己创建的django用户名中有urls.py这个文件在这个里面配置

from django.contrib import admin
from django.urls import path
from django.urls.conf import include

urlpatterns = [
    path(‘admin/‘, admin.site.urls),
    path(‘appa1/‘,include(‘app01.urls‘)),
    path(‘appb1/‘,include(‘app02.urls‘))
]

urls

然后创建app :        python  manage.py  startapp +自己起的名字 

创建完成后在自己创建的app下再创建urls.py

from django.urls import path
from . import views

urlpatterns = [
    path(‘indexa/‘,views.indexa),

二级目录下urls

完成后在自己创建的app中找到views.py文件

from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.

def index(request):
    return HttpResponse(‘哈喽你个哈皮‘)

二级目录下views

 

 

相关推荐