I am trying to install pip3 install django-allauth to prevent login before email confirmation, but at moment when setting up settings.py I get the following error. I don't want to rename all the project names, because it is going to affect the complete project. Is there a way to achieve this without too many changes?
xxxxxx#xxxxxx:~/Documents/blackowl$ python3 manage.py makemigrations account
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/xxxxxx/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_com
mand_line
utility.execute()
File "/home/xxxxxx/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
django.setup()
File "/home/xxxxxx/.local/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/xxxxxx/.local/lib/python3.6/site-packages/django/apps/registry.py", line 95, in populate
"duplicates: %s" % app_config.label)
django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: account
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'allauth' ,
'allauth.account' ,
'allauth.socialaccount' ,
'allauth.socialaccount.providers.github' ,
'apps.website',
'apps.account'
]
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 = 'blackowl.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',
],
},
},
]
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)
Try to add this under INSTALLED_APPS :
'django.contrib.account'
Related
I am using Django 4.0
I have written two standalone apps. Foo and FooBar.
Application Foo uses package django_nyt. Application FooBar uses functionality from application Foo.
I am able to makemigrations and migrate models in application Foo, however, when working with application FooBar, when I attempt to makemigrations, I get the following error trace:
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_from_command_line(sys.argv)
File "/path/to/project/foobar/env/lib/python3.8/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/path/to/project/foobar/env/lib/python3.8/site-packages/django/core/management/__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/path/to/project/foobar/env/lib/python3.8/site-packages/django/core/management/base.py", line 414, in run_from_argv
self.execute(*args, **cmd_options)
File "/path/to/project/foobar/env/lib/python3.8/site-packages/django/core/management/base.py", line 460, in execute
output = self.handle(*args, **options)
File "/path/to/project/foobar/env/lib/python3.8/site-packages/django/core/management/base.py", line 98, in wrapped
res = handle_func(*args, **kwargs)
File "/path/to/project/foobar/env/lib/python3.8/site-packages/django/core/management/commands/makemigrations.py", line 100, in handle
loader = MigrationLoader(None, ignore_no_migrations=True)
File "/path/to/project/foobar/env/lib/python3.8/site-packages/django/db/migrations/loader.py", line 58, in __init__
self.build_graph()
File "/path/to/project/foobar/env/lib/python3.8/site-packages/django/db/migrations/loader.py", line 276, in build_graph
self.graph.validate_consistency()
File "/path/to/project/foobar/env/lib/python3.8/site-packages/django/db/migrations/graph.py", line 198, in validate_consistency
[n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
File "/path/to/project/foobar/env/lib/python3.8/site-packages/django/db/migrations/graph.py", line 198, in <listcomp>
[n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
File "/path/to/project/foobar/env/lib/python3.8/site-packages/django/db/migrations/graph.py", line 60, in raise_error
raise NodeNotFoundError(self.error_message, self.key, origin=self.origin)
django.db.migrations.exceptions.NodeNotFoundError: Migration foo.0001_initial dependencies reference nonexistent parent node ('django_nyt', '0010_auto_20220802_2211')
contents of /path/to/proj/foo/env/lib/python3.8/site-packages/django_nyt/migrations/0010_auto_20220802_2211
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('django_nyt', '0009_alter_foo_subscription_and_more'),
]
operations = [
migrations.AlterField(
model_name='notification',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='settings',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='subscription',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
]
Since these are standalone apps, I am using the design pattern advocated for in Django Standalone Reusable Libraries.
common.py (foo application)
from pathlib import Path
from django.conf import settings
SAMPLE_PROJECT_DIR_NAME='sample_project'
BASE_DIR = f"{Path(__file__).parent.resolve()}/{SAMPLE_PROJECT_DIR_NAME}"
STANDALONE_APP_NAME='foo'
STATIC_URL = '/static/'
INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.admin',
'django.contrib.messages',
'django.contrib.humanize',
'django.contrib.sites',
'django_nyt.apps.DjangoNytConfig',
STANDALONE_APP_NAME,
'myapp',
]
SECRET_KEY="lskfjklsdfjalkfslfjslfksdjfslkfslkfj"
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
DEBUG=True
# AUTH_USER_MODEL='testdata.CustomUser',
DATABASES={
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': f"{BASE_DIR}/db.sqlite3",
},
}
SITE_ID=1
ROOT_URLCONF=f"{SAMPLE_PROJECT_DIR_NAME}.urls"
TEMPLATES=[
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'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.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.messages.context_processors.messages',
]
},
},
]
USE_TZ=True
MIDDLEWARE=[
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
]
settings.configure(
SECRET_KEY=SECRET_KEY,
DEFAULT_AUTO_FIELD = DEFAULT_AUTO_FIELD,
DEBUG=DEBUG,
# AUTH_USER_MODEL=AUTH_USER_MODEL,
DATABASES=DATABASES,
SITE_ID=SITE_ID,
ROOT_URLCONF=ROOT_URLCONF,
INSTALLED_APPS=INSTALLED_APPS,
STATIC_URL=STATIC_URL,
TEMPLATES=TEMPLATES,
USE_TZ=USE_TZ,
MIDDLEWARE=MIDDLEWARE,
)
common.py (foobar)
import sys
from pathlib import Path
from django.conf import settings
SAMPLE_PROJECT_DIR_NAME='sample_project'
PARENT_DIR = f"{Path(__file__).parent.parent.resolve()}"
BASE_DIR = f"{Path(__file__).parent.resolve()}/{SAMPLE_PROJECT_DIR_NAME}"
STANDALONE_APP_NAME='foobar'
STATIC_URL = '/static/'
sys.path.insert(0, f"{PARENT_DIR}/django-foo")
INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.admin',
'django.contrib.messages',
'django.contrib.humanize',
'django.contrib.sites',
'django_nyt.apps.DjangoNytConfig',
'foo',
STANDALONE_APP_NAME,
'myapp',
]
SECRET_KEY="lskfjklsdfjalkfslfjslfksdjfslkfslkfj"
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
DEBUG=True
# AUTH_USER_MODEL='testdata.CustomUser',
DATABASES={
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': f"{BASE_DIR}/db.sqlite3",
},
}
SITE_ID=1
ROOT_URLCONF=f"{SAMPLE_PROJECT_DIR_NAME}.urls"
TEMPLATES=[
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'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.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.messages.context_processors.messages',
]
},
},
]
USE_TZ=True
MIDDLEWARE=[
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
]
FOOBAR_DATA={}
settings.configure(
SECRET_KEY=SECRET_KEY,
DEFAULT_AUTO_FIELD = DEFAULT_AUTO_FIELD,
DEBUG=DEBUG,
# AUTH_USER_MODEL=AUTH_USER_MODEL,
DATABASES=DATABASES,
SITE_ID=SITE_ID,
ROOT_URLCONF=ROOT_URLCONF,
INSTALLED_APPS=INSTALLED_APPS,
STATIC_URL=STATIC_URL,
TEMPLATES=TEMPLATES,
USE_TZ=USE_TZ,
MIDDLEWARE=MIDDLEWARE,
FOOBAR_DATA = FOOBAR_DATA,
)
manage.py (same for both foo and foobar standalone applications)
import os
import sys
import django
from common import *
sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), SAMPLE_PROJECT_DIR_NAME))
django.setup()
if __name__ == '__main__':
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
I have looked in the migrations folders for both applications and this is what I found:
foo app has the migration 0010_auto_20220802_2211 generated, and applied to django_nyt, to change the PK auto fields to use BigInteger.
foobar app does not have the migration file 0010_auto_20220802_2211 generated for django_nyt (hence the migration error). I can't for the life of me, work out why foobar is not using the migrations generated by foo, since it has a dependency on foo.
A no-brainer hack would be to simply copy over the missing migration file, but that is too fragile, and I want to actually understand what is going on, and why foobar is not using/applying the migrations created by a dependency.
This is what I have tried so far (did not resolve the issue):
I checked in the migration files for foo. Initially, I had kept them out of the repository
Created a dummy model class in foobar, that explicitly had a dependency on a model in dyango_nyt - the reasoning being that, if a django_nyt model existed in foobar, i would force migrations to be created for django_nyt.
This is what my dummy class in foobar/models.py looked like:
from django_nyt.models import Notification
class FooBarMigrationHack(Notification):
name = models.CharField(max_length=10)
None of the above has worked, and I'm still getting the same error stack trace as shown above, in my question.
How do I resolve this without having to manually copy the 'missing' migration file from foo/migrations/ to foobar/migrations/ ?
I am getting an error on the login page when I log out.
ValueError at /accounts/login/
dictionary update sequence element #0 has length 0; 2 is required
I do not know why I get this error because I've never had such an error before. What does this error mean and how can I solve it?
traceback
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/accounts/login/?next=/
Django Version: 3.1.4
Python Version: 3.8.10
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'register',
'customer',
'financial_analysis',
'ocr',
'core',
'approvals',
'crispy_forms',
'ckeditor',
'rest_framework',
'requests',
'ckeditor_uploader',
'django_filters',
'activity_log',
'djmoney',
'djmoney.contrib.exchange',
'mathfilters',
'bootstrap3',
'phone_field']
Installed 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']
Traceback (most recent call last):
File "C:\Users\USER\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Users\USER\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\django\core\handlers\base.py", line 202, in _get_response
response = response.render()
File "C:\Users\USER\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\django\template\response.py", line 105, in render
self.content = self.rendered_content
File "C:\Users\USER\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\django\template\response.py", line 83, in rendered_content
return template.render(context, self._request)
File "C:\Users\USER\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\django\template\backends\django.py", line 61, in render
return self.template.render(context)
File "C:\Users\USER\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\django\template\base.py", line 168, in render
with context.bind_template(self):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\contextlib.py", line 113, in __enter__
return next(self.gen)
File "C:\Users\USER\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\django\template\context.py", line 244, in bind_template
updates.update(processor(self.request))
Exception Type: ValueError at /accounts/login/
Exception Value: dictionary update sequence element #0 has length 0; 2 is required
register/urls.py
from django.conf.urls import url
from django.conf.urls.static import static
from django.urls import path, include
from CreditReviewBot import settings
from . import views
from .views import update_user
urlpatterns = [
url(r'^signup/$', views.signup, name='signup'),
path('', views.home, name='home'),
path('accounts/', include('django.contrib.auth.urls')),
url(r'^accounts/(?P<id>\d+)/update/$', update_user, name="update"),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
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.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'approvals.views.approval_context_processor',
],
},
},
]
I've a app name cz.
Error:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\ashis\PycharmProjects\ChatZone\venv\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\ashis\PycharmProjects\ChatZone\venv\lib\site-packages\django\core\management\__init__.py", line 377, in execute
django.setup()
File "C:\Users\ashis\PycharmProjects\ChatZone\venv\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\ashis\PycharmProjects\ChatZone\venv\lib\site-packages\django\apps\registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "C:\Users\ashis\PycharmProjects\ChatZone\venv\lib\site-packages\django\apps\config.py", line 116, in create
mod = import_module(mod_path)
File "C:\Users\ashis\AppData\Local\Programs\Python\Python38\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'allauth.accountallauth'
This is my settings.py file:
from pathlib import Path
from django.template.backends import django
import os
import allauth
BASE_DIR = Path(__file__).resolve(strict=True).parent.parent
DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'cz',
'allauth',
'allauth.account'
'allauth.socialaccount',
'allauth.socialaccount.providers.google',
]
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 = 'ChatZone.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 = 'ChatZone.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
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',
},
]
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)
SITE_ID = 1
LOGIN_REDIRECT_URL = '/'
SOCIALACCOUNT_PROVIDERS = {
'google': {
'SCOPE': [
'profile',
'email',
],
'AUTH_PARAMS': {
'access_type': 'online',
}
}
}
My urls.py for the project ChatZone:
from django.contrib import admin
from django.urls import path,include
from django.views.generic import TemplateView
import allauth
urlpatterns = [
path('', TemplateView.as_view(template_name='cz/index.html')),
path('admin/', admin.site.urls),
path('accounts/', include('allauth.urls')),
path('cz/',include('cz.urls')),
]
I've tried many approach to solve this problem but I don't know how to solve it. I've searched everywhere but I can't find this module in my code. How can I tackle these kinds of problems in the future?
You've missed a comma. Very common typo:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'cz',
'allauth',
'allauth.account' # no comma here
'allauth.socialaccount',
'allauth.socialaccount.providers.google',
]
So you want:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'cz',
'allauth',
'allauth.account', # comma added
'allauth.socialaccount',
'allauth.socialaccount.providers.google',
]
you can specify which version of python your web app uses -3.7, 3.8. choose a python version that you have installed the package, be sure the same.
pip 3.8 install --user allauth
after that create a virtualenv and virtualenv's using the python version and then
pip install allauth
I am new to Django, and I just took over from another developer on this project. All I have done so far is clone the code from git and install the dependencies.
Immediately after setting up the project, and running python manager.py runserver and going to localhost:8000/admin I get an error stating the TypeError at /admin/login/, 'CsrfViewMiddleware' object is not iterable:
Traceback:
File
"/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/core/handlers/exception.py"
in inner
39. response = get_response(request)
File
"/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/core/handlers/base.py"
in _legacy_get_response
249. response = self._get_response(request)
File
"/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/core/handlers/base.py"
in _get_response
217. response = self.process_exception_by_middleware(e, request)
File
"/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/core/handlers/base.py"
in _get_response
215. response = response.render()
File
"/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/template/response.py"
in render
109. self.content = self.rendered_content
File
"/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/template/response.py"
in rendered_content
86. content = template.render(context, self._request)
File
"/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/template/backends/django.py"
in render
66. return self.template.render(context)
File
"/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/template/base.py"
in render
206. with context.bind_template(self):
File "/usr/lib/python3.5/contextlib.py" in __enter__
59. return next(self.gen)
File
"/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/template/context.py"
in bind_template
236. updates.update(processor(self.request))
Exception Type: TypeError at /admin/login/
Exception Value: 'CsrfViewMiddleware' object is not iterable
I would post code from the source code but I can't figure where in the source the cause of this might possibly be.
My settings.py:
import os
from datetime import datetime
from django.conf.global_settings import EMAIL_USE_SSL
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'ourapp',
'social.apps.django_app.default',
'sendgrid',
'corsheaders',
)
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',
'ourapp.middleWare.authenticationMiddleware.AuthenticationMiddleware'
)
ROOT_URLCONF = ''
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.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.middleware.csrf.CsrfViewMiddleware',
'corsheaders.middleware.CorsMiddleware',
'social.apps.django_app.context_processors.backends',
'social.apps.django_app.context_processors.login_redirect',
],
},
},
]
(Sorry about the lack of indentation.)
Any ideas on how to proceed from here would be greatly appreciated!
Try removing 'django.middleware.csrf.CsrfViewMiddleware', from TEMPLATES. Probably 'corsheaders.middleware.CorsMiddleware', too
I was trying internationalization/localization in django.
I am getting an error while i am trying to make the '.po' files using the command
./manage.py makemessages
relevant parts from settings.py
import os
from django.utils.translation import ugettext_lazy as _
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls.apps.PollsConfig'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'sampleproject.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',
'django.template.context_processors.i18n'
],
},
},
]
WSGI_APPLICATION = 'sampleproject.wsgi.application'
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
LANGUAGES = [
('fi-FI', _('Finnish')),
('en', _('English')),
]
LOCALE_PATHS = [
os.path.join(BASE_DIR, 'locale'),
]
relevant parts from urls.py
urlpatterns += i18n_patterns(
url(r'^$', home, name='home'),
url(r'^admin/', include(admin.site.urls)),
url(r'^polls/', include('polls.urls')),
)
here is the traceback.
Traceback (most recent call last):
File "./manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/project/Myapps/for_sample/lib/python3.4/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/project/Myapps/for_sample/lib/python3.4/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/project/Myapps/for_sample/lib/python3.4/site-packages/django/core/management/base.py", line 305, in run_from_argv
self.execute(*args, **cmd_options)
File "/project/Myapps/for_sample/lib/python3.4/site-packages/django/core/management/base.py", line 356, in execute
output = self.handle(*args, **options)
File "/project/Myapps/for_sample/lib/python3.4/site-packages/django/core/management/commands/makemessages.py", line 361, in handle
potfiles = self.build_potfiles()
File "/project/Myapps/for_sample/lib/python3.4/site-packages/django/core/management/commands/makemessages.py", line 393, in build_potfiles
self.process_files(file_list)
File "/project/Myapps/for_sample/lib/python3.4/site-packages/django/core/management/commands/makemessages.py", line 488, in process_files
self.process_locale_dir(locale_dir, files)
File "/project/Myapps/for_sample/lib/python3.4/site-packages/django/core/management/commands/makemessages.py", line 507, in process_locale_dir
build_file.preprocess()
File "/project/Myapps/for_sample/lib/python3.4/site-packages/django/core/management/commands/makemessages.py", line 113, in preprocess
content = templatize(src_data, self.path[2:])
File "/project/Myapps/for_sample/lib/python3.4/site-packages/django/utils/translation/__init__.py", line 214, in templatize
return _trans.templatize(src, origin)
File "/project/Myapps/for_sample/lib/python3.4/site-packages/django/utils/translation/trans_real.py", line 670, in templatize
"%s (%sline %d)" % (t.contents, filemsg, t.lineno)
SyntaxError: Translation blocks must not include other block tags: blocktrans count var|length as count (file htmlcov/_project_Myapps_for_sample_lib_python3_4_site-packages_django_templatetags_i18n_py.html, line 1073)
Dev Setup:
Django 1.10
Python 3.4.5
As this is my first question in SO, pardon me if there's any mistake :)
Thanks in advance :)
The error occurred because of the htmlcov folder which was generated while running the coverage script.
Removed that folder and executed the following commands to generate the '.po' files.
./manage.py makemessages -l fi
and the following command to generate the '.mo' files.
./manage.py compilemessages