Application labels aren't unique, duplicates: staticfiles - python

I'm having trouble figuring out what I'm duplicating here. I'm trying to migrate my files so I can deploy on Heroku. It says that "staticfiles" is duplicated, but I can't see where the conflict is. Does migration need to be done in order to deploy? or is there something wrong with my database?
import dj_database_url
import os
ALLOWED_HOSTS = ['127.0.0.1', '.herokuapp.com']
INSTALLED_APPS = [
'whitenoise.runserver_nostatic',
'wiki_app',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.postgres',
]
MIDDLEWARE = [
'whitenoise.middleware.WhiteNoiseMiddleware',
'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 = 'coding_dojo_final_project.urls'
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',
],
},
},
]
WSGI_APPLICATION = 'coding_dojo_final_project.wsgi.application'
...
WHITENOISE_USE_FINDERS = True
...
STATIC_URL = '/static/'
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

You need to set a static root which is where Django compiles the static files for serving in production when you run python manage.py collectstatic. The name must be different than the location of your static files in your project.
STATIC_ROOT = str(BASE_DIR.joinpath('staticfiles'))
See the docs for more info.

Related

ImportError: No module named menu

I'm trying to customize the admin interface with django-admin-tools.
I'm following https://django-admin-tools.readthedocs.io/en/latest/customization.html
The menu.py has been created successfully with python manage.py custommenu in my project directory.
I have then renamed it to Mymenu.py
When I add ADMIN_TOOLS_MENU = 'project_name.Mymenu.CustomMenu' to my settings.py, as indicated I get the follwoing error: ImportError: No module named menu
my settings.py
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__)))
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'admin_tools',
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'admin_platform',
'colorful',
]
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',
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'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',
],
'loaders': [ 'admin_tools.template_loaders.Loader',
('django.template.loaders.cached.Loader', [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
]),
]
},
},
]
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR,'static')
STATICFILES_FINDERS = ['django.contrib.staticfiles.finders.AppDirectoriesFinder']
ADMIN_TOOLS_MENU = 'myProject.Mymenu.CustomMenu'
I solved it by replacing ADMIN_TOOLS_MENU = 'project_name.Mymenu.CustomMenu' simply by ADMIN_TOOLS_MENU = 'Mymenu.CustomMenu'
I am assuming you have created the app using the following command,
python manage.py startapp custommenu
and then renamed the views.py to Mymenu.py
in that case you need to write custommenu in your installed apps instead of Mymenu

No module named rest_authusers error

I am in the process of adding allauth to my project, following this tutorial:
http://django-allauth.readthedocs.org/en/latest/installation.html
When trying to make migrations I get the following error:
"ImportError: No module named rest_authusers"
My settings.py is as follows:
# 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',
'rest_auth'
'users',
# The Django sites framework is required
'django.contrib.sites',
'allauth.socialaccount.providers.facebook',
)
SITE_ID = 1
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',
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(SETTINGS_PATH, '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',
# `allauth` needs this from django
'django.template.context_processors.request',
],
},
},
]
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',
)
AUTH_USER_MODEL = 'users.UserProfile'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
)
}
Am furthermore not sure how to fix this as there is no reference of authusers in my project files.
Traceback: https://dpaste.de/2SDB
You simply forgot to put the comma after 'rest_auth' ;)

Settings.py not working as expected Django

Good evening, I am facing a weird problem with my django project. From my Ubuntu, where I started to develop it, I didn't find any issue around it, but when I tried to move it in my OS X El Capitan, then I'm either receiving one of this error:
1) When APP_DIRS is set to True: app_dirs must not be set when loaders is defined.
2) When APP_DIRS is set to False or removed: No module named 'admin_tools.template_loaders'
Is there anything that I'm doing bad in this settings.py?
That's how my settings.py looks like:
SITE_ID = 1
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'admin_tools',
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
'tinymce',
'crispy_forms',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.sites',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'management',
'myApp',
'easy_thumbnails',
)
TINYMCE_DEFAULT_CONFIG = {
'plugins': "table,spellchecker,paste,searchreplace",
'theme': "advanced",
'cleanup_on_startup': True,
'custom_undp_redo_levels': 10,
}
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',
)
ROOT_URLCONF = 'myproject.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'debug': DEBUG,
'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',
'django.template.context_processors',
],
'loaders': [
('django.template.loaders.cached.Loader', [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
]),
'admin_tools.template_loaders.Loader',
]
},
},
]
WSGI_APPLICATION = 'myproject.wsgi.application'
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
AUTH_USER_MODEL = 'management.IfasicUser'
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
)
LOGIN_URL = 'django.contrib.auth.views.login'
LOGIN_REDIRECT_URL = 'home'
MEDIA_URL = '/media/'
STATIC_URL = '/static/'
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
CRISPY_TEMPLATE_PACK = 'bootstrap3'
Any help will be gladly appreciated.
When App_DIRS is set to True: app_dirs must not be set when loaders is defined.
As the error says, you must remove the app_dirs setting when you define loaders.
When APP_DIRS is set to False or removed: No module named 'admin_tools.template_loaders'
Try upgrading to 0.7.1, which was released today. Looking at the changelog, there appears to be a bug with the cached template loader.

why would django not find templates for installed 3rd party apps that are in site-packages?

I recently spun off an old project and tried installing its apps (which worked) and also installing django-helpdesk/bootstrap_forms. But django could find neither helpdesk templates, or bootstrapform templates. My settings.py looks like:
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'key'
DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'accounts',
'index',
'taggit',
'helpdesk',
'bootstrapform',
)
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',
)
HELPDESK_PATH = "/home/cchilders/.local/virtualenv/new_bookmarks/lib/python2.7/site-packages/helpdesk/templates",
BOOSTRAPFORM_PATH = "/home/cchilders/.local/virtualenv/new_bookmarks/lib/python2.7/site-packages/bootstrapform/templates"
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, "templates"),
"/home/cchilders/.local/virtualenv/new_bookmarks/lib/python2.7/site-packages/helpdesk/templates",
"/home/cchilders/.local/virtualenv/new_bookmarks/lib/python2.7/site-packages/bootstrapform/templates",],
'APP_DIRS': False,
'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',
],
},
},
]
STATIC_ROOT = '/home/cchilders/django_practice/new_bookmarks/static'
STATIC_URL = '/static/'
I don't have an issue now, but am very confused as to why I had to manually do HELPDESK_PATH and BOOSTRAPFORM_PATH. The last time I spun this up, installing the apps worked out the box, with the same TEMPLATE configs. I have these installed:
Django==1.8.3
argparse==1.2.1
betterpath==0.2.2
django-bootstrap-form==3.2
django-extensions==1.5.5
django-helpdesk==0.1.16
django-markdown-deux==1.0.5
django-mptt==0.7.4
django-taggit==0.16.2
email-reply-parser==0.3.0
ipython==3.2.1
l==0.3.1
lxml==3.4.4
markdown2==2.3.0
pytz==2015.4
requests==2.7.0
simplejson==3.8.0
six==1.9.0
vcversioner==2.14.0.0
wsgiref==0.1.2
zope.interface==4.1.2
I am running a VE (like I was when it found templates) and packages are where expected:
~/.local/virtualenv/new_bookmarks/lib/python2.7/site-packages/bootstrapform/templates
When turning off the new URLS back to 'DIRS': [os.path.join(BASE_DIR, "templates"), ], I get
TemplateDoesNotExist at /helpdesk/
helpdesk/public_homepage.html
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
/home/cchilders/django_practice/new_bookmarks/templates/helpdesk/public_homepage.html (File does not exist)
and I don't get why it isn't checking the usual places. My VE works, if I deactive it I can't runserver due to missing packages like 'taggit'. What usually causes django to ignore site-packages and not look for templates beyond BASE_DIR/templates? Thank you

Getting TemplateDoesNotExist from Django 1.8

** I'm using Django 1.8. The templates feature has changed in this release of Django. Read more here Upgrading templates to Django 1.8**
This is bothering me because I've come across this issue and fixed it for one of my other projects, but I can't for the life of me figure out how to fix it this time around. I've gone through countless stackoverflow questions and tried to resolve the issue using the answers provided by I've had no luck. This is the error message I am getting:
Exception Type: TemplateDoesNotExist
Exception Value:
index.html
Exception Location: /Library/Python/2.7/site-packages/django/template/loader.py in get_template, line 46
Python Executable: /usr/bin/python
Python Version: 2.7.6
Python Path:
['/Users/User1/Documents/PyCharmProjects/Project1',
It seems that is it looking in the wrong folder, it should be looking under Project1/templates according to my settings.py file:
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_PATH = os.path.join(BASE_DIR, '/templates/')
TEMPLATE_DIRS = (
TEMPLATE_PATH,
)
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
#'django.template.loaders.eggs.load_template_source',
)
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_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',
)
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',
)
ROOT_URLCONF = 'Project1.urls'
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',
],
},
},
]
My templates folder is in the root folder of my project. What's the issue here? I have given it a TEMPLATE_DIRS parameter, and used a proper BASE_DIR, which is what the majority of the answers recommend.
remove the slashes: TEMPLATE_PATH = os.path.join(BASE_DIR, 'templates')
See here
Things have changed with Django 1.8, in which the template system has been improved. See the release notes.
In your settings.py add:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [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',
],
},
},
]
the code above comes straight from one of my projects.
Feel free to use os.path.join(BASE_DIR, 'templates') instead of catenating the strings.
1) If your route for templates is project_name/app_name/templates/app_name
'DIRS': [os.path.join(BASE_DIR, 'app_name', 'templates', 'app_name')],
2) If your route for templates is project _name/templates or project_name/app_name/templates_only
'DIRS': [#leave it just empty, will work fine],
Note: 'template_only' means that templates/*.html there is no any folder inside templates.
I would try placing TEMPLATE_PATH in DIRS:
TEMPLATES =[
{....
'DIRS' : [TEMPLATE_PATH,],
....

Categories