I am trying to use oauth2 authentication using django oauth toolkit. I got the following exception :
Could not import 'oauth2_provider.ext.rest_framework.OAuth2Authentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'
My settings.py file looks like :
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'adaccounts',
'corsheaders',
'clients',
'Gen42Backend',
'djcelery',
'oauth2_provider'
)
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'oauth2_provider.ext.rest_framework.OAuth2Authentication',
)
}
In case anyone has the same problem.
Replace:
oauth2_provider.ext.rest_framework.OAuth2Authentication
With:
oauth2_provider.contrib.rest_framework.OAuth2Authentication
Related
hello guys what the difference between this two syntax
'blog' and 'blog.apps.BlogConfig'
in project this is located in installed app.
I think both are same but there should be difference between this 2 commands because they looks like different
first one is this
INSTALLED_APPS = [
'blog',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
seccond one is :
INSTALLED_APPS = [
'blog.apps.BlogConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
I assume that you have a custom configuration(BlogConfig) for your app.
You have at least two options to register the app with custom config in project settings(INSTALLED_APPS).
(if)You have a variable default_app_config = 'blog.apps.BlogConfig' in blog/__init__.py file, then inserting blog into INSTALLED_APPS will be the same as blog.apps.BlogConfig. If you don't have it in __init__.py, BlogConfig won't be applied in the example below.
INSTALLED_APPS = [
...,
'blog',
...,
]
(if)You have an empty __init__.py in your app. Then to apply the custom config you must include the path to config.
INSTALLED_APPS = [
...,
'blog.apps.BlogConfig',
...,
]
putting only blog in the second example will work without the custom config.
I got error:
django.db.utils.IntegrityError: insert or update on table "auth_permission" violates foreign key constraint "auth_content_type_id_508cf46651277a81_fk_django_content_type_id"
DETAIL: Key (content_type_id)=(1) is not present in table "django_content_type".
I found this post but no recommendation helps:
ContentType.objects.clear_cache()
move 'django.contrib.contenttypes' before 'django.contrib.auth' in INSTALLED_APPS
Has anyone found a solution to this problem?
For details: my settings.py
INSTALLED_APPS = (
'django.contrib.contenttypes',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.postgres',
'webpack_loader',
'rest_framework',
'corsheaders',
'common',
'humans',
'validations',
'accounts',
'comments',
'errors',
'django_nose',
'reports',
'dashboards',
'cacheops',
'djcelery',
)
INSTALLED_APPS=(
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
.....
.....
)
can you change the order. reset the db run migrate again.
the error I've got is :
RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
My setting file is like this:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'disqus',
]
SITE_ID = 1
DISQUS_API_KEY = 'kLA0JWWljFwKTHvSym2oSRIlBSDCZZmReyx9NeIzPz48rtwS6Ew2vVewmZgupsea'
DISQUS_WEBSITE_SHORTNAME = 'foobar'
I'm having the following Django apps structure:
sarpedon33
rango
migrations
sarpedon33
media
static
templates
I get this comment "App 'rango' could not be found. is it in INSTALLED_APPS?" when I try to makemigrations for rango app.
settings.py is like this :
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_PATH = os.path.join(BASE_DIR,'static')
STATIC_URL = '/static/' # You may find this is already defined as such.
STATICFILES_DIRS = (STATIC_PATH,)
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') # Absolute path to the media directory
SECRET_KEY = '****************************************************'
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',
)
Add the rango app to the INSTALLED_APPS:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rango', # <--- HERE ----
)
In case anyone got here because they are seeing this error even though they actually have the app listed in INSTALLED_APPS, like it was my case working with legacy code.
Do not use project_dir.app_name, or any similar structure. Write only the app name, e.g.:
This is wrong:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'directory.my_app_name',
)
This is correct:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'my_app_name',
)
I'm using oscar and added from fork order app. After added that cant run syncdb or server. It is giving an error import error: No module named 'project\\order'
from oscar import get_core_apps
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.flatpages',
'django.contrib.sites',
'compressor',
] + get_core_apps(['project\order'])
SITE_ID = 1
this is my installed apps. I didnt understand why it doing this.
This get_core_apps(['project\order']) should be get_core_apps(['project.order']).
I changed project to oscar.apps.order and it did work. But why, it is a question for me.