1创建项目 first_pro
2创建app app01
做一个登录页面的web项目,浏览器输入一个网址得到一个web页面
用户: http:127.0.0.1:8001/login/
1urls.py
from django.conf.urls import url from django.contrib import admin from app01 import views
urlpatterns = [
# url(r‘^admin/‘, admin.site.urls),
url(r‘^index/‘, views.index), #配置路径,r‘^/index/‘,这个前置导航斜杠不需要添加.
]
2写逻辑视图
from django.shortcuts import render,HttpResponse # Create your views here.
def index(request): print(request.method) #‘POST‘ ‘GET‘ if request.method == ‘GET‘:
return render(request,‘login.html‘) else:
# print(request.GET) print(request.POST)
username = request.POST.get(‘username‘) password = request.POST.get(‘password‘)
if username == ‘dazhuang‘ and password == ‘123‘: return HttpResponse(‘登录成功!‘)
else:
return HttpResponse(‘登录失败!‘)
3创建html文件
在templates文件夹中创建一个login.html文件