I am using django 1.6.4 and django toolbar version django-debug-toolbar==1.2.
I do get the toolbar on the side but when I click on any of the menu items, it shows me the html elements from my home page within the toolbar overlay. I have done collectstatic after installing django toolbar. HTML generated is not valid but issue seems to be from the css and scripts tag from django toolbar.
Any help will be much appreciated.
Thanks
Updated:
urls.py entry
if settings.DEBUG:
import debug_toolbar
urlpatterns += patterns('',
url(r'^__debug__/', include(debug_toolbar.urls)),
)
settings.py
DEBUG = True
MIDDLEWARE_CLASSES = (
'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',
'debug_toolbar.middleware.DebugToolbarMiddleware',
)
THIRD_PARTY_APPS = (
'suit',
'debug_toolbar',
'south',
'crispy_forms',
'haystack',
'taggit',
)
Related
I am trying to use django-allauth & django-allauth-2fa in my Django app.
My django-allauth app is set uo correctly - everything is working as expected.
However, when trying to set up django-allauth-2fa I ran into some issues: Configuring a two-factor authentification at accounts/two_factor/setup/ when I scan the QR code, input the token generated and press verify the page simply reloads with a new QR code instead of leading me to the next step in the Two-Factor configuration workflow. I can't figure out what my mistake may be, as I set up everything as written in the django-allauth-2fa documentation
My Pipfile:
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
django = "==3.0.0"
pylint = "==2.4.4"
django-crispy-forms = "==1.9"
django-allauth = "==0.42.0"
django-allauth-2fa = "==0.8"
[requires]
python_version = "3.7"
my settings.py file:
...
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
# Local
'users.apps.UsersConfig',
'pages.apps.PagesConfig',
#Third-party
'allauth',
'allauth.account',
'django_otp',
'django_otp.plugins.otp_totp',
'django_otp.plugins.otp_static',
'allauth_2fa',
'crispy_forms',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django_otp.middleware.OTPMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'allauth_2fa.middleware.AllauthTwoFactorMiddleware',
]
SITE_ID = 1
ACCOUNT_ADAPTER = 'allauth_2fa.adapter.OTPAdapter'
...
my urls.py file:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('accounts/', include('allauth_2fa.urls')),
path('accounts/', include('allauth.urls')),
path('', include('pages.urls')),
]
And I also ran python manage.py migrate
had the same problem on Ubuntu20 . Fix it with enbaling automatic sync date & times.
By default django messages framework does not localize it's messages correctly.
For example in admin interface
As you can see all other things in admin panel are localized. The translation file exists. Here is my settings.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
...
]
MIDDLEWARE = [
'debug_toolbar.middleware.DebugToolbarMiddleware',
'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',
'django.middleware.locale.LocaleMiddleware',
]
LANGUAGE_CODE = 'ru' # I've tried 'ru-RU'
TIME_ZONE = 'Europe/Moscow'
USE_I18N = True
USE_L10N = True
USE_TZ = True
How to fix this? Thanks in advance. I have django version 3.0.6. This error also is absent in django 1.8
It was a breaking change from django/django#42b9a23 (Django 3.0+) that only updated the French translations.
You can patch DjangoTranslation.gettext to handle the smart quotes.
def _patch_gettext():
from django.utils.translation.trans_real import DjangoTranslation
_gettext = DjangoTranslation.gettext
def gettext(self, message):
text = _gettext(self, message)
if text is message and '“' in message:
new_message = message.replace('“', '"').replace('”', '"')
new_text = _gettext(self, new_message)
if new_text is not new_message:
return new_text
return text
DjangoTranslation.gettext = gettext
About patching
Subclass AppConfig in mysite/apps.py:
from django.apps import AppConfig
class MySiteAppConfig(AppConfig):
name = 'mysite'
def ready(self):
_patch_gettext()
Put the dotted path to that subclass in INSTALLED_APPS in mysite/settings.py:
INSTALLED_APPS = [
...
'mysite.apps.MySiteAppConfig',
]
Reference: https://docs.djangoproject.com/en/3.0/ref/applications/#configuring-applications
I want to translate my website to other language , i've configured my settings.py as it should be but no changes are happens.
I've created messages and i can see them inside my local folder, also i've compiled them successfully without any erors.
Here is my settings :
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# My apps
'main',
# Third part apps
'captcha',
'jsonify'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
LOCAL_PATHS = (
os.path.join(BASE_DIR, 'locale'),
)
LANGUAGE_CODE = 'en'
LANGUAGES = (
('ru', _(u'RU')),
('en', _(u'EN'))
)
My views:
from django.utils.translation import gettext as _
def main(request):
context = {
'title':_('Главная'),
}
return render(request, 'index.html', context)
Also i've loaded the i18n above inside my template where the translations happens index.html:
{% load static %}
{% load i18n %}
<title>{% block head_title %}{{title}}{% endblock %}</title>
I got it to work, instead of typing LOCALE_PATHS i typed LOCAL_PATHS, now everything is working just fine .
Django 1.9.6 i18n works perfect when I open the browser and change language.
But I want to save language and the other times when user comes it will be in his/her prefered language.
Now when I open the site it always redirect me to /en .I tried to change my settings and set
LANGUAGE_CODE='ru'
or something else but it does not work here is my settings file
ALLOWED_HOSTS = []
LOGIN_URL=reverse_lazy('login')
AUTH_USER_MODEL='custom.MyUser'
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'custom',
'languages',
]
MIDDLEWARE_CLASSES = [
'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.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'builtcustom.urls'
WSGI_APPLICATION = 'builtcustom.wsgi.application'
LANGUAGES=(
('en',_('ENGLISH')),
('fr',_('FRENCH')),
('cs', _('czech')),
('hy', _('ARMENIAN')),
('ru', _('RUSSIAN')),
)
LOCALE_PATHS = (
os.path.join(BASE_DIR, 'locale'),
)
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ =False
How can i solve this problem and redirect to url with a language that I want(Dynamically selected from database)??
For a particular url you an select language like this in Django.
from django.utils.translation import activate
activate('fr') # To use french
Checkout the documentation.
You can easily get whatever language you want from the database and call activate on it. Make sure your the languages in database has same abbreviations as in Django.
I read Django tutorial but found nothing related to never expiring session.
Requirement - User should logged out only if he/she initiate by clicking on logout.
How can I solve this issue?
My django project settings related to session -
INSTALLED_APPS = (
..
'django.contrib.sessions',
..
)
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
'rest_framework.authentication.BasicAuthentication',
#'rest_framework.authentication.SessionAuthentication',
)
}
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',
)
AUTHENTICATION_BACKENDS = (
"django.contrib.auth.backends.ModelBackend",
"allauth.account.auth_backends.AuthenticationBackend",
)
By default Django keeps sessions between browser closes. You can modify this behavior with the SESSION_EXPIRE_AT_BROWSER_CLOSE setting.
https://docs.djangoproject.com/en/1.8/topics/http/sessions/#browser-length-vs-persistent-sessions