I've overriden Django-allauth templates in my Django project just creating a new folder "account" in templates folder. This works during deployment on Windows but when I moved the project to DigitalOcean VPS, it is looking for old templates (in allauth app) so I see old styled allauth pages.
This is the structure:
firstapp\
authapp\
templates\
account\
email.html
login.html
anotherapp\
I tried to switch allauth apps and my authapp in INSTALLED_APPS but it doesn't seem to work.
And this is my settings.py INSTALLED_APPS.
INSTALLED_APPS = (
'django.contrib.auth',
'mainapp',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.sites',
'django.contrib.staticfiles',
'crispy_forms',
'super_inlines',
'django_tables2',
'quizzesapp',
'ordersapp',
'django_extensions',
'authapp',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google',
'allauth.socialaccount.providers.facebook',
'languagesapp',
'widget_tweaks',
'localflavor',
'paypal',
'paypal.standard.ipn',
'nested_inline',
'django_forms_bootstrap'
)
What do you thing I should do?
EDIT:
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.i18n',
# 'django.core.context_processors.request',
# "django.contrib.auth.context_processors.auth",
# "allauth.account.context_processors.account",
# "allauth.socialaccount.context_processors.socialaccount",
],
},
},
]
Related
I've read many answers but I don't know what am I missing.
I did the same steps as they are mentioned in Django Docs (https://docs.djangoproject.com/en/3.0/ref/contrib/admin/#admin-overriding-templates) but nothing happened.
Here is my actual configuration :
INSTALLED_APPS = [
'app1.apps.App1Config',
'app2.apps.App2Config',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
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 = 'rida.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],#i modified this line
'APP_DIRS': False, #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',
],
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
]
}
}
]
the contents of admin.py file of app1 :
from django.contrib import admin
from django.conf.urls import url
from app1.models import Modele
admin.site.register(Modele)
I want to override the template base.html, so I copied it from django\contrib\admin\templates\admin and put it in myproject\templates\admin\app1, then I made some changes on this file but nothing happened, so I have no idea why it doesn't work and what am I missing.
thank you in advance.
I tried serving my static files using whitenoise, but still not getting any of my css/js loading in my pages.
I ran collectstatic after enabling whitenoise and static folder was generated.
I tried using both
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
and django's ManifestStaticFilesStorage backend.
Here are my settings
INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'whitenoise.runserver_nostatic',
'django.contrib.staticfiles',
'django.contrib.humanize',
'crispy_forms',
'classroom',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'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 = 'django_school.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 = 'django_school.wsgi.application'
...
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'public/static'),
]
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
This is how my project is structured
home
-->etc
-->thegradientboostmvp
---->classroom
---->django-app
---->public
>static
>admin
>css
>img
>vendor
>second
>third
>fourth
---->static
------>admin
------>css
------>img
------>second
>css
>js
>img
------>third
>css
>js
>img
------>fourth
>img
>js
>css
---->templates
in my case putting my static folder in public_html solved.
when I change DEBUG = False my page CSS styles not work.
also, I set allowed hosts but no difference made.
ALLOWED_HOSTS = ['localhost']
I use djngo2.2 and here is part of my setting.py:
DEBUG = False
ALLOWED_HOSTS = ['localhost']
# Application definition
INSTALLED_APPS = [
'matab',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
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 = 'labsolutions.urls'
TEMPLATE_DIR= os.path.join(BASE_DIR,'media/template/')
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',
],
},
},
]
WSGI_APPLICATION = 'labsolutions.wsgi.application'
STATIC_URL = '/static/'
STATICFILES_DIRS=(
os.path.join(BASE_DIR,'media/static/'),
)
STATIC_ROOT = os.path.join(BASE_DIR,'statcifiles')
If you are in developement and you want to serve the static while setting DEBUG=False then you need to launch the server using the insecure option
python manage.py runserver --insecure
Of course it is only valid for development
I know there are multiple questions on this site about this problem, but I cannot find a solution.
I am using Python 3.6 (anaconda) + django 2.0.2 on Windows 10.
I am following the tutorial: https://docs.djangoproject.com/en/2.0/intro/tutorial03/
Here is my views.py
from django.shortcuts import render
# Create your views here.
from django.http import HttpResponse
from .models import *
def index(request):
content = 'abcxyz'
context = {'content': content}
return render(request, 'polls/index.html', context)
I created a file index.html in the folder polls\templates\polls
My settings.py:
INSTALLED_APPS = [
'polls.apps.PollsConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
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 = 'django_site.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 = 'django_site.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
I have a problem of 'TemplateDoesNotExist' - it seems to me that django tries to look for a template in
django.template.loaders.app_directories.Loader: /mnt/e/workspace/capec-processing/code/django_site/polls/templates/polls/templates/polls/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /home/user_name/anaconda3/envs/capec/lib/python3.6/site-packages/django/contrib/admin/templates/polls/templates/polls/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /home/user_name/anaconda3/envs/capec/lib/python3.6/site-packages/django/contrib/auth/templates/polls/templates/polls/index.html (Source does not exist)
I am not sure what did I do wrong, because I followed the tutorial on the django website.
Could you suggest me a hint?
Update
Here is the structure of the my root directory (called django_site):
django_site
--django_site
----settings.py
--polls
----templates
------polls
--------index.html
----views.py
--db.sqlite3
--manage.py
In your setting.py you need to add this
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls' # You need to add this too. This should be same as your app name.
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, "templates")], # Add this to your settings file
'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',
],
},
},
]
And your template folder should be here
myproject/
|-- myproject/
| |-- polls/
| |-- myproject/
| |-- templates/ <-- here!
| | |-- polls/
| | | |-- index.html
| | |-- base.html
| | +-- home.html
| +-- manage.py
+-- venv/
change value of DIRS under TEMPLATES to this to tell django to look for templates in your app directory.
'DIRS': [os.path.join(BASE_DIR, 'templates'),],
and then you can either put templates parallel to manage.py or under specific app directory.
+app
-+__init__.py
-+templates
---+polls
-----+index.html
change your order of the installed apps in your settings
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls.apps.PollsConfig',
]
All you need to do is add the name of your app, i.e. polls, to the list of installed apps in the settings.py file and reload the URL to the app index page. I don't know why the Django tutorial still does not include this step as it trips everyone up, every time.
settings.py
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls',
]
I had installed and configured django-admin-tools 0.8 following the documentation. Django version is 1.11.4, using virtualenv in project.
File settings.py:
INSTALLED_APPS = [
'admin_tools',
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
'django.contrib.auth',
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'atelierapp',
]
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': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'admin_tools.template_loaders.Loader',
]
},
},
]
File urls.py:
urlpatterns = [
#url(r'^admin/', admin.site.urls),
url(r'^admin_tools/', include('admin_tools.urls')),
]
But when I try to enter the admin panel, I get a 404 error.
Screenshot
What is the problem I'm not seeing?
Thank you for your time.
According to the documentation
Prerequisite
In order to use django-admin-tools you obviously need to have configured your Django admin site. If you didn’t, please refer to the relevant django documentation.
However I noticed in your urls that you have:
#url(r'^admin/', admin.site.urls),
Have you tried removing the # tag?