add polls

This commit is contained in:
baoliang 2020-08-20 00:39:10 +08:00
parent 3659ffeff7
commit b031dab5c5
3 changed files with 18 additions and 19 deletions

1
.gitignore vendored
View File

@ -3,4 +3,5 @@
.media/
*/__pycache__/
*/*.pyc
*/migrations
NewMediaMonitoring/local_settings.py

View File

@ -4,5 +4,7 @@ from . import views
urlpatterns = [
path('', views.index, name='index'),
path('status_500', views.status_500, name='status_500'),
path('status_401', views.status_401, name='status_401'),
path('login', views.polls_login, name='polls_login'),
]

View File

@ -1,14 +1,24 @@
from django.shortcuts import render
from django.http import HttpResponse
from django.http import HttpResponse, JsonResponse
from django.contrib.auth import get_user_model
from django.views.decorators.csrf import csrf_exempt
from django_token.models import Token
# Create your views here.
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
username = request.GET.get('username')
password = request.GET.get('password')
print(username, password)
return JsonResponse({'status': 'error', 'message': '用户名或密码错误'})
def status_500(request):
return HttpResponse(status=500)
def status_401(request):
return HttpResponse(status=401)
@csrf_exempt
@ -24,22 +34,8 @@ def polls_login(request):
u = authenticate(request, username=user.username, password=password)
if u is not None:
login(request, u)
token = Token.objects.create(user=myuser)
print(u)
result = dict()
result['id'] = user.id
result['username'] = user.username
result['email'] = user.email
result['role'] = ','.join(roles)
if teacher:
school = teacher.school.title
r = get_region(school)
if r:
result['regionId'] = r[0]
result['regionName'] = r[1]
result['unitId'] = r[2]
result['unitName'] = r[3]
result['teacher'] = {'name': teacher.name, 'school': school}
return JsonResponse(result)
else:
return JsonResponse({'status': 'error', 'message': '用户名或密码错误'})