状況
acc
HttpResponse
のみを使用しますdecorators.py
from Django.http import HttpResponse
from Django.shortcuts import redirect
def unauthenticated_user(view_func):
def wrapper_func(request, *args, **kwargs):
if request.user.is_authenticated:
return redirect('home')
else:
return view_func(request, *args, **kwargs)
return wrapper_func
def allowed_users(allowed_roles=[]):
def decorator(view_func):
def wrapper_func(request, *args, **kwargs):
group = None
if request.user.groups.exists():
group = request.user.groups.all()[0].name
if group in allowed_roles:
return view_func(request, *args, **kwargs)
else:
return HttpResponse('Authorized')
return wrapper_func
return decorator
[〜#〜]エラー[〜#〜]
Settings.pyがPostgreSQLを使用しているときにログインした場合。ログアウトすると、すべてが正常に動作します。 SQL liteを使用すると、ログインでき、すべてが完全に機能します
ValueError at /
The view accounts.decorators.wrapper_function didn't return an HttpResponse object. It returned None instead.
Request Method: GET
Request URL: http://localhost...
Django Version: 3.0
Exception Type: ValueError
Exception Value: The view accounts.decorators.wrapper_function didn't return an HttpResponse object. It returned None instead.
Exception Location: /Users/.../python3.7/site-packages/Django/core/handlers/base.py in _get_response, line 126
Python Executable: /Users/.../bin/python3
Python Version: 3.7.3
.....
Request information
USER MYUSERNAME
GET No GET data
POST No POST data
FILES No FILES data
COOKIES ...
...
解決しようとしました
python manage.py migrate
それはRunning migrations: No migrations to apply.
python manage.py loaddata db.json
DoesNotExist at /register/
Group matching query does not exist.
これが私がそれを解決した方法です。
Home › Authentication and Authorization › Groups › customer
...
accounts customer can view customer
...