Closed whitebumblebee closed 3 years ago
I just tried a fresh install with the quickstart-tutorial and then installed django-rest-passwordreset from pip and I encountered no such issues.
Have you installed everything from pip or directly from the repo? How does your project-structure look like? Could you post your settings.py?
Yes, i installed it with pip. My project structure looks something like this:
.
├── manage.py
├── assets
│ └── uni.svg
├── fabfile.py
├── fixtures
│ ├── initialReviewData.json
│ ├── initialRoleData.json
│ └── initialUserData.json
├── maintenance_off.html
├── templates
│ └── admin
├── frontend
│ ├── admin.py
│ ├── apps.py
│ ├── __init__.py
│ ├── models.py
│ ├── templates
│ ├── tests.py
│ ├── views.py
│ ├── src
│ ├── urls.py
│ ├── __pycache__
│ ├── migrations
│ └── static
├── static
│ ├── 137-1370051_avatar-generic-avatar-hd-png-download.png
│ ├── 428-4287240_no-avatar-user-circle-icon-png.png
│ ├── admin
│ ├── avatar-default-icon.png
│ ├── css
│ ├── img
│ ├── logorac.svg
│ ├── rest_framework
│ ├── unc.svg
│ ├── beolar.jpg
│ └── frontend
├── reviews
│ ├── apps.py
│ ├── __init__.py
│ ├── tests.py
│ ├── views.py
│ ├── admin.py
│ ├── models.py
│ ├── migrations
│ ├── urls.py
│ ├── serializers.py
│ ├── utils.py
│ ├── api.py
│ └── __pycache__
├── backend
│ ├── __init__.py
│ ├── wsgi.py
│ ├── asgi.py
│ ├── static
│ ├── prod_settings.py
│ ├── dev_settings.py
│ ├── local_settings.py
│ ├── urls.py
│ ├── settings.py
│ └── __pycache__
└── accounts
├── apps.py
├── __init__.py
├── managers.py
├── tests.py
├── views.py
├── drf_utils.py
├── exceptions.py
├── models.py
├── migrations
├── forms.py
├── admin.py
├── serializers.py
├── urls.py
├── api.py
└── __pycache__
And my settings.py file looks something like this:
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "jdiewjdewjfdjwfkdjf;lrejf;lekf;lkeqf;lkew;lfdkew"
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = [*]
# Application definition
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
# Installed apps
"rest_framework",
"knox",
"django_rest_passwordreset",
"whitenoise.runserver_nostatic",
# Created apps
"accounts",
"reviews",
"frontend",
]
REST_FRAMEWORK = {
"DEFAULT_AUTHENTICATION_CLASSES": ("knox.auth.TokenAuthentication",),
"EXCEPTION_HANDLER": "rest_framework.views.exception_handler",
# 'EXCEPTION_HANDLER':'accounts.exceptions.custom_exception_handler',
}
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]
ROOT_URLCONF = "backend.urls"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(BASE_DIR, "templates")],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]
WSGI_APPLICATION = "backend.wsgi.application"
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
"default": {
"ENGINE": "django.db.backends.mysql",
"NAME": "reviews_db",
"USER": "xyz",
"PASSWORD": "xxxxxxxxx",
"HOST": "localhost",
"OPTIONS": {
"init_command": "SET foreign_key_checks = 0; "
"SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ",
"isolation_level": "repeatable read",
},
},
}
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",},
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",},
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",},
]
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
LANGUAGE_CODE = "en-us"
TIME_ZONE = "Asia/Kolkata"
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
REACT_APP_DIR = os.path.join(BASE_DIR, "frontend")
STATICFILES_DIRS = (os.path.join(BASE_DIR, "assets"),)
STATIC_URL = "/static/"
AUTH_USER_MODEL = "accounts.Employee"
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
try:
from .local_settings import *
except ImportError as e:
print(e)
EMAIL_HOST = "mail.xyz.com"
SERVER_EMAIL = "xyz1@xyz.com"
DEFAULT_FROM_EMAIL = "xyz2l@xyz.com"
DEFAULT_EMAIL_RECIPIENTS = []
I just tried installing it, then putting it inside INSTALLED_APPS in settings.py file and then tried the command python manage.py migrate
and got above error. I dont what I am doing wrong.
Hmm, this appears to be a tricky one, I don't immediately see what is wrong. Could you please go through the quickstart-tutorial, test if everything works according to the tutorial and after that, install django-rest-passwordreset
, add it to the INSTALLED_APPS and then run the migrations? I assume you will not have the same problem there. Maybe we can find the difference between the two projects this way.
I had a similar error when upgrading. Found out that it was due to my user model importing the following:
from django_rest_passwordreset.models import ResetPasswordToken
from ... import ...
The solution was to move the import from the top of my user model to an inline import like:
class MyUser:
def reset_password(self):
from django_rest_passwordreset.models import ResetPasswordToken
# your code
Hope this helps!
@Roconda thanks for the solution
This is related to how Django is loading Apps and Models. You would get the same issue if you try to load a model in a custom queryset module for a manager.
I am trying to use it and following documentation. After adding it to INSTALLED_APPS inside settings.py file, when I try to run
python manage.py migrate
as shown in documentation, I get following error. Am I doing something wrong or missing something?