views
from django.shortcuts import render, HttpResponse, redirect # Create your views here. def index(request): return HttpResponse('Index') # 账号密码验证 """ def login(request): if request.method =="GET": return render(request,'login.html') elif request.method == "POST": u = request.POST.get('user') p = request.POST.get('pwd') if u == 'sooele' and p =='123': return redirect('/index') else: return render(request, 'login.html') else: return redirect('/index/') """ # 单选择 """ def login(request): if request.method =="GET": return render(request,'login.html') elif request.method == "POST": v = request.POST.get('gender') print(v) return render(request, 'login.html') else: return redirect('/index/') """ # 多 """ def login(request): if request.method == "GET": return render(request, 'login.html') elif request.method == "POST": v = request.POST.get('favor') print(v) return render(request, 'login.html') else: return redirect('/index/') """ # 文件接收 """ def login(request): if request.method == "GET": return render(request, 'login.html') elif request.method == "POST": # radio # v = request.POST.get('gender') # print(v) # v = request.POST.getlist('favor') # print(v) # v = request.POST.get('fafafa') # print(v) obj = request.FILES.get('fafafa') print(obj,type(obj),obj.name) import os file_path = os.path.join('upload', obj.name) f = open(file_path, mode="wb") for i in obj.chunks(): f.write(i) f.close() from django.core.files.uploadedfile import InMemoryUploadedFile return render(request, 'login.html') else: # PUT,DELETE,HEAD,OPTION... return redirect('/index/') """
url
"""day19 URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/2.1/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: path('', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin from django.urls import path from app01 import views urlpatterns = [ path(r'admin/', admin.site.urls), path(r'index/', views.index), path(r'login/', views.login), ]