test2
DjangoURL路径注意
urlpatterns = [
path('admin/', admin.site.urls),
path('index',views.index), #在路径末尾加 '/' 例如:index/
path('login',views.login),
]
def index(request):
return render(request, 'index.html')
def login(request):
if request.method == 'GET':
return render(request, 'login.html')
elif request.method == 'POST':
u = request.POST.get('user',None)
p = request.POST.get('pwd',None)
if u == 'alex' and p == '123':
return redirect('/index')
else:
return render(request, 'login.html')
else:
return redirect('/index') # 调用时候也不要在后面加斜杠否则会出错