from django.contrib import auth from django.contrib.auth.models import User from django.shortcuts import render, redirect, HttpResponse from django.contrib.auth.decorators import login_required # Create your views here. def login(request): if request.method == 'GET': return render(request, 'login.html') else: username = request.POST.get('username') print(username) password = request.POST.get('password') print(password) obj = auth.authenticate(request, username=username, password=password) print(obj) if obj: auth.login(request, obj) return HttpResponse('ok') return HttpResponse('no') def register(request): if request.method == 'GET': return render(request, 'register.html') else: User.objects.create_user(username=request.POST.get('username'),password=request.POST.get('password')) return HttpResponse('ok') def logout(request): auth.logout(request) return HttpResponse('ok') @login_required def index1(request): return HttpResponse('index1 is ok')