I have installed and configured django-admin-tools-stats as mentioned on https://django-admin-tools-stats.readthedocs.io/en/latest/index.html
However I can not generate any graph, or no widget for graphs is visible on my admin interface.
My settings.py
INSTALLED_APPS = (
#Admin Dashboard
'admin_tools',
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
#For the admin interface statistics
'admin_tools_stats',
'django_nvd3',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'django.contrib.admin',
'rest_framework',
#Rest-auth
'rest_framework.authtoken',
'rest_auth',
#Rest-auth registration
'allauth',
'allauth.account',
'rest_auth.registration',
#Following is added to allow cross domain requests i.e. for serving requests those are coming from frontend app
'corsheaders',
#Admin reg stats
'admin_user_stats',
'chart_tools',
#'djangobower',
'flights',
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
#'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',
'django.core.context_processors.request',
],
'loaders': (
'admin_tools.template_loaders.Loader',
#'django.template.loaders.filesystem.load_template_source',
#'django.template.loaders.app_directories.load_template_source',
'django.template.loaders.app_directories.Loader',
#'django.template.loaders.filesystem.Loader',
),
},
},
]
#To use custom admin dashboard, edit dashboard.py file to make any changes
ADMIN_TOOLS_INDEX_DASHBOARD = 'dashboard.CustomIndexDashboard'
ADMIN_TOOLS_APP_INDEX_DASHBOARD = 'dashboard.CustomAppIndexDashboard'
What could be the reason?
Have you added django-admin-tools to your urls.py file like below -
urlpatterns = patterns('',
url(r'^admin_tools/', include('admin_tools.urls')),
#...other url patterns...
)
And make sure to migrate it using -
python manage.py migrate
Related
I just deployed my website on Heroku, an integral part of the functionality of the site is to receive post requests from another website of mine. I'm using DRF's TokenAuthentication for my authentication. In my local environment everything works perfectly, but the same cannot be said for the live website. Whenever I send a POST request I receive a 401 error, the new token is added to the request's header and the data is exactly the same as the data used in the local environment. Any help would be gladly appreciated.
views.py
class PetCreateView(CreateAPIView):
serializer_class = PetSerializer
permission_classes = [IsAuthenticated, ]
def perform_create(self, serializer):
if Breed.objects.filter(user_id=self.request.POST.get('breed_name', None)).exists():
pass
else:
Breed.objects.create( breed_name=self.request.POST.get('breed_name', None),
size=self.request.POST.get('size', None),
temperament=self.request.POST.get('temperament', None),
energy=self.request.POST.get('energy', None),
hypoallergenic=self.request.POST.get('hypoallergenic', None))
breed = Breed.objects.get(breed_name=self.request.POST.get('breed_name', None))
# Assigns a groomer the created Pet
groomer = assign_groomer(breed)
serializer.save(groomer=groomer, breed=breed)
SpaReport.objects.create(breed=breed, groomer=groomer)
settings.py
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'bootstrap3',
'captcha',
'django_celery_beat',
'django_celery_results',
'mathfilters',
'storages',
'account',
'sales',
'scrty',
'analytics'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'pettracker.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_DIR, ],
'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',
'scrty.context_processors.from_settings',
],
},
},
]
WSGI_APPLICATION = 'pettracker.wsgi.application'
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.TokenAuthentication',
],
}
I have done all the necessary settings in settings.py, and i have set the urls too i the urls.py file. Each time i am trying to access /accconts/login, it will say the url did not match any pattern, and it redirects me to /accounts/profile.
This are the code
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'core'
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['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',
],
},
},
]
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)
SITE_ID = 1
urlpatterns = [
path('accounts/', include('allauth.urls'))
]
Thanks for the reply. I was able to solve the problem. The way allauth works you must not be logged in while accessing /accounts/login.
What i did was to go to /accounts/logout/ and then logout before the /accounts/login will go
By default django-allauth divert logged in users from the login page.
You can use a couple of settings to fix the issue :
SET the ACCOUNT_AUTHENTICATED_LOGIN_REDIRECTS to FALSE
or
SET LOGIN_REDIRECT_URL to 'the desired path' for logged in users in the settings.py file.
https://django-allauth.readthedocs.io/en/latest/configuration.html
When I log in with the wrong/right credentials I don't just get a simple form error or login I go a full debug error page
https://imgur.com/a/KxR5pIo
I have all auth fully installed and provider Google is working for signup and login. I'm also doing this on the allauth standardized login form and URL. Please let me know if I should post any more info besides the pictures.
settings.py
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.contrib.auth.context_processors.auth',
# `allauth` needs this from django
'django.template.context_processors.request',
'django.contrib.messages.context_processors.messages',
],
'libraries': {
'staticfiles': 'django.templatetags.static',
},
},
},
]
AUTHENTICATION_BACKENDS = (
# Needed to login by username in Django admin, regardless of `allauth`
'django.contrib.auth.backends.ModelBackend',
# `allauth` specific authentication methods, such as login by e-mail
'allauth.account.auth_backends.AuthenticationBackend',
)
ACCOUNT_AUTHENTICATION_METHOD = 'username_email'
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
ACCOUNT_ADAPTER = "allauth.account.adapter.DefaultAccountAdapter"
# Application definition
INSTALLED_APPS = [
'dal',
'dal_select2',
# Django Specific
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
# django-allauth
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google',
# Make sure 'collectfast' is in INSTALLED_APPS, before 'django.contrib.staticfiles'
'collectfast',
'django.contrib.staticfiles',
'django.contrib.sites',
# Packages / Modules
'ckeditor',
'ckeditor_uploader',
'rest_framework',
'storages',
'flatpickr',
# Local apps
'portfolios',
]
SITE_ID = 3
LOGIN_REDIRECT_URL = 'dash'
LOGOUT_REDIRECT_URL = 'home'
ACCOUNT_LOGOUT_ON_GET = True
SIGNUP_REDIRECT_URL = 'dash'
I'm using the collectfast package https://github.com/antonagestam/collectfast and the custom backend settings were interfering with the django-allauth package. I can comment this part out when the app is live and only uncomment it when I need to collect static.
Not the best fix but a step in the right direction.
CACHES = {
'default': {
# Your default cache
},
'collectfast': {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'TIMEOUT': None,
'OPTIONS': {
'MAX_ENTRIES': 5000,
}
}
}
I'm trying to install django-admin-tools in my existing Django installation. So far so good except for the fact that the backend looks fuzzy and afters some inspection it seems that utils.js is missing:
If I look into my static directory (after running python manage.py collectstatic) the file simply isn't there (it is in the installed Python package so I don't know if it's supposed to be there anyway but it might be a clue)
I think the problem might be related with my configuration, here some snippets of it:
MEDIA_URL = '/'
STATIC_ROOT = os.path.join('static')
STATIC_URL = '/static/'
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
INSTALLED_APPS = (
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'blog',
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
'django.core.context_processors.request',
'django.core.context_processors.static',
],
},
},
]
Django is 1.8.1
I'm wondering if anyone has some suggestions to fix this.
I've managed to fix this so for possible future readers:
The documentation (http://django-admin-tools.readthedocs.org/en/latest/configuration.html) states that django-admin-tools is modular. I thought that configuring installed apps with the above configuration was correct, it wasn't.
Although all the installed components seemed to work. Collectstatic probably couldn't find all the required files (files that belong to the base 'admin-tools' app).
The solution was to add 'admin-tools' to installed_apps so it looks like:
INSTALLED_APPS = (
'admin_tools',
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
(...)
)
I'm trying to create a data visualization for yahoo finances, which I've successfully done locally using Django 1.9.2. It scrapes yahoo finances and then uses D3 to create bubble charts with tooltips.
However, the bubbles don't show up:
https://pure-woodland-72284.herokuapp.com/
This is what appears in Heroku logs.
Heroku Log Error Messages
DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework_swagger',
'mysite'
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
# insert your TEMPLATE_DIRS here
os.path.join(os.path.dirname(__file__), 'templates'),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
# Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
# list if you haven't customized them:
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
],
},
},
]
REST_FRAMEWORK={
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
]
}
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
Your console have the following errors:
Mixed Content: The page at 'https://pure-woodland-72284.herokuapp.com/' was loaded over HTTPS, but requested an insecure stylesheet 'http://fonts.googleapis.com/css?family=Lobster+Two:400,700italic'. This request has been blocked; the content must be served over HTTPS.
Hence you are getting 'Uncaught ReferenceError: $ is not defined' error since you did not really imported your libraries
So I'm guessing that you have imported your scripts (jquery,d3.tip,cssfonts) from their cdn and used http while importing. Try importing them with https and see if that solves your problem