Situation
acc
HttpResponse
that the error message containsdecorators.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
ERROR
If I log in while settings.py uses PostgreSQL. If I log out everything works out fine again. If I use SQL lite I can log in and everything works perfectly
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 ...
...
Tried to Solve
python manage.py migrate
it says Running migrations: No migrations to apply.
python manage.py loaddata db.json
DoesNotExist at /register/
Group matching query does not exist.
Not sure I can help, but I have a Mac, use Django and had some problems with PostgreSQL, so I'll share my ideas.
First, it seems to me that the problem is indeed the connection with the database, not the code. I looked up your error in the Django code, it says:
def _get_response(self, request):
"""
Resolve and call the view, then apply view, exception, and
template_response middleware. This method is everything that happens
inside the request/response middleware.
"""
...
# Complain if the view returned None (a common error).
if response is None:
...
raise ValueError(
"The view %s.%s didn't return an HttpResponse object. It "
"returned None instead." % (callback.__module__, view_name)
)
Although I'm certainly not an expert on middleware, apparently Django is not receiving data from your database.
I once had problems with different versions of PostgreSQL on my Mac. You can check in /Library/PostgreSQL, I have two directories (11 and 12), so I have to be careful which one I use for my projects. In PgAdmin you can see both versions. If you have old versions or want to reinstall PostgreSQL (which is pretty drastic but would give you a clean sheet), there is a good manual here: https://medium.com/@zoefhall/effectively-uninstall-and-reinstall-psql-with-homebrew-on-osx-fabbc45c5d9d. You can check the version that your Django is using by typing in your Shell:
python3 manage.py shell -c "from django.db import connection; print(connection.cursor().connection.server_version)"
For me the result is 110005, which translates into 11.0.5.
I also had problems with psycopg2 several times. Installation of it is necessary when you set up your virtual environment with Django, so if you managed that, then probably that went ok. The problem I had was that it couldn't find the config file, and the easiest solution for me was to install the binary version psycopg2-binary. But if you want a specific version of PostgreSQL on your Mac, then you need to put the pg_config file in your PATH, see https://www.psycopg.org/docs/install.html.
That's what I have learned, I hope it helps you a little bit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With