Django translations not working with Django-cms and djangocms-blog - django

I have a problem with my Django Translations.
My Django doesn't translate my tags.
I use django-cms and in django-cms I have a plugin djangocms-blog.
Django == 1.6.5
Django-cms == 3.0.3
Djangocms-blog == 0.2b5
My transtags are not translated.
Example tag:
{% trans "read more" %}
I installed everything correctly, my settings.py contains this:
gettext = lambda s: s
# Internationalization
LANGUAGE_CODE = 'nl'
TIME_ZONE = 'Europe/Brussels'
USE_I18N = True
USE_L10N = True
USE_TZ = True
LOCALE_PATHS = (
os.path.join(BASE_DIR, 'locale'),
)
LANGUAGES = (
('nl', _(u'Dutch')),
('fr', _(u'French')),
('en', _(u'English')),
)
CMS_LANGUAGES = {
1: [
{
'code': 'nl',
'name': gettext('Dutch'),
'fallbacks': ['en', 'fr'],
'public': True,
'hide_untranslated': True,
'redirect_on_fallback':False,
},
{
'code': 'en',
'name': gettext('English'),
'fallbacks': ['nl'],
'public': False,
'hide_untranslated': True,
'redirect_on_fallback':False,
},
{
'code': 'fr',
'name': gettext('French'),
'public': False,
'hide_untranslated': True,
},
],
2: [
{
'code': 'nl',
'name': gettext('Dutch'),
'public': True,
'fallbacks': ['en'],
},
],
'default': {
'fallbacks': ['en', 'fr'],
'redirect_on_fallback': True,
'public': False,
'hide_untranslated': False,
}
}
In My Middleware classes:
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
'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',
'django.middleware.doc.XViewMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.user.CurrentUserMiddleware',
'cms.middleware.toolbar.ToolbarMiddleware',
'cms.middleware.language.LanguageCookieMiddleware',
)
My urls.py:
from django.conf.urls import include, url
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
from django.conf import settings
admin.autodiscover()
urlpatterns = i18n_patterns(
'',
url(r'^i18n/', include('django.conf.urls.i18n')),
url(r'^admin/', include(admin.site.urls)),
url(r'^products/', include('catalog.urls')),
url(r'^contact/', 'contact.views.contact'),
url(r'^pages/', include('django.contrib.flatpages.urls')),
url(r'^taggit_autosuggest/', include('taggit_autosuggest.urls')),
url(r'^', include('cms.urls')),
)
if settings.DEBUG:
import debug_toolbar
urlpatterns = i18n_patterns('',
url(r'^__debug__/', include(debug_toolbar.urls)),
url(r'^404/$', 'django.views.defaults.page_not_found'), # TODO MOET NOG VERPLAATST WORDEN
url(r'^500/$', 'django.views.defaults.server_error'), # TODO MOET NOG VERPLAATST WORDEN
url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
url(r'', include('django.contrib.staticfiles.urls')),
) + urlpatterns
In my blog_items.html page (a page from the djangocms-blog plugin template that I override)
{% load i18n thumbnail cms_tags %}
{% load url from future %}
I created my languages within the virtual env by
Going to the virtual env by "workon app"
I run the command django-admin.py makemessages -l nl (the po files are created correctly)
I run the command django-admin.py compilemessages and everything seems fine
In the root of my program is the locale folder with 3 subfolders: en, fr and nl. They contain all the LC_MESSAGES folder with a django.mo and django.po file with the correct message strings.
#: .\templates\djangocms_blog\includes\blog_item.html:37 #, fuzzy
msgid "read more"
msgstr "lees meer"

This is solved.
First of all the fuzzy had to be removed.
I had to add the parler settings correct into my general settings:
In the documentation of Django-parler (https://pypi.python.org/pypi/django-parler ) they suggest the next settings:
PARLER_LANGUAGES = {
None: (
{'code': 'nl',},
{'code': 'en',},
{'code': 'fr',},
),
}
Instead of
PARLER_LANGUAGES = {
1: (
{'code': 'nl',},
{'code': 'en',},
{'code': 'fr',},
),
}

AFAIK translations marked as fuzzy are not compiled in the mo files and you must "unfuzzy" them before being available

Related

Django CMS page tree default language

It seems I don't understand how to set the default language for Django CMS. I want the default language to be set to Dutch. However, for an unknown reason, it always defaults to English when creating or after modifying/editing a Page.
Take the following scenario. I open the Page tree. English is selected by default. I select Dutch. I edit this page. I publish it. I click on edit, it opens the English page which is empty.
Take another scenario. I open the Page tree. I create a new page. By default it opens for the English variant.
Note: All cookies were removed as suggested in the documentation.
Please advise how I can set the default language to Dutch?
The settings:
from django.utils.translation import gettext_lazy as _
LANGUAGE_CODE = "nl"
SITE_ID = 1
USE_I18N = True
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"corsheaders.middleware.CorsMiddleware",
"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.common.BrokenLinkEmailsMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
'cms.middleware.user.CurrentUserMiddleware',
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.toolbar.ToolbarMiddleware',
'cms.middleware.language.LanguageCookieMiddleware',
]
LANGUAGES = [
('nl', 'Dutch'),
('en', 'English'),
]
CMS_LANGUAGES = {
1: [
{
'code': 'nl',
'name': _('Dutch'),
'fallbacks': ['en', ],
'public': True,
'hide_untranslated': True,
'redirect_on_fallback': False,
},
{
'code': 'en',
'name': _('English'),
'public': True,
},
],
'default': {
'fallbacks': ['nl', 'en'],
'redirect_on_fallback': False,
'public': True,
'hide_untranslated': True,
}
}
I fixed the problem as follows per the documentation:
# urls.py
from django.conf.urls.i18n import i18n_patterns
from django.views.i18n import JavaScriptCatalog
# ...
admin.autodiscover()
urlpatterns = i18n_patterns(
re_path(r'^jsi18n/$', JavaScriptCatalog.as_view(), name='javascript-catalog'),
)
# Note the django CMS URLs included via i18n_patterns
urlpatterns += i18n_patterns(
path(settings.ADMIN_URL, admin.site.urls),
re_path(r'^', include('cms.urls')),
)
urlpatterns += [
...
]
This setup introduces other minor issues that need to be fixed. But in general, this is the solution.
On another note, not sure though as to why this part is needed:
re_path(r'^jsi18n/$', JavaScriptCatalog.as_view(), name='javascript-catalog')

Django Allauth not included in URL Conf through template links but URL is functional

I am new to using AllAuth and somewhat new to Django. I am developing a site and wanted to overhaul the custom user authentication that I was using before. I have implemented AllAuth into an existing solution. Everything seems to be connecting, but the template links are not working and I get returned a 404 error:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/url%20'account_login'
Using the URLconf defined in QuoteTool.urls, Django tried these URL patterns, in this order:
admin/
[name='home']
accounts/
form/ [name='entryForm']
form/success [name='success']
quotes/ [name='quotes']
The current path, url 'account_login', didn’t match any of these.
For example in my Navbar
...
{% if user.is_authenticated %}
<div class="m-2">
<h6>Hello,
{{ request.user.firstName }}!</h6>
</div>
<a class="btn btn-outline-secondary" href=" url 'account_logout' ">Logout</a>
{% else %}
<a class="btn btn-outline-secondary" href=" url 'account_login' ">Login</a>
<a class="btn btn-primary ml-2 mr-2" href=" url 'account_signup' ">Sign Up</a>
{% endif %}
...
These links do not work! I am not understanding why not. Especially since if I manually type the URL "http://127.0.0.1:8000/accounts/login/" it returns and renders the proper page with my custom template.
My url.py file is as follows
from django.contrib import admin
from django.urls import path, include
from QuoteTool import views
from accounts import a_views
from forms import f_views
from quotes import q_views
urlpatterns = [
path('admin/', admin.site.urls, name = 'django-admin'),
#index
path('', views.baseView, name= 'home'),
#accounts
path('accounts/', include('allauth.urls')), # new
#forms
path('form/', f_views.entryForm, name = 'entryForm'),
path('form/success', f_views.success, name = 'success'),
#quotes
path('quotes/', q_views.viewQuotes, name = 'quotes'),
And my settings.py is as follows
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['127.0.0.1', 'localhost']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin', #admin app - default
'django.contrib.auth', #authentication app - default
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'accounts', #user accounts - new
'forms', #user inputted forms - new
'quotes', #program output from froms - new
'crispy_forms', #lovely forms
'allauth', #3rd Party Auth
'allauth.account', #3rd Party Auth
'allauth.socialaccount', #3rd Party Auth
]
CRISPY_TEMPLATE_PACK = 'bootstrap4'
MESSAGE_TAGS = {
messages.DEBUG: 'alert-info',
messages.INFO: 'alert-info',
messages.SUCCESS: 'alert-success',
messages.WARNING: 'alert-warning',
messages.ERROR: 'alert-danger',
}
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 = 'QuoteTool.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 = 'QuoteTool.wsgi.application'
# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
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',
},
]
# Internationalization
# https://docs.djangoproject.com/en/4.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR,'static'),]
STATIC_ROOT = os.path.join(BASE_DIR,'assets')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
# Custom User Model
AUTH_USER_MODEL = 'accounts.newUser'
ACCOUNT_FORMS = {'signup': 'accounts.forms.NewUserForm'}
# config/settings.py
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
LOGIN_REDIRECT_URL = 'home'
ACCOUNT_LOGOUT_REDIRECT_URL = 'home'
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",
)
SITE_ID = 1
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_SIGNUP_PASSWORD_ENTER_TWICE = True
ACCOUNT_SESSION_REMEMBER = True
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_UNIQUE_EMAIL = True
Any help would be greatly appreciated, thank you!

django-tinymce doesn't show up in admin

I can't get the django-tinymce module gui to show up in the admin of my django project.
Here's settings.py (tinymce settings are at the end):
import os
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'XXXXXXXXXXXX'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'notices.apps.NoticesConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis',
'imagekit',
'leaflet',
'nested_admin',
'tinymce'
]
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 = 'orag.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 = 'orag.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'xxxxxx',
'NAME': 'xxxxxx',
'USER': 'xxxxxx',
'PASSWORD': 'xxxxxx',
'HOST': 'localhost'
}
}
# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
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',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/
LANGUAGE_CODE = 'fr-FR'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL = 'static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_URL = 'media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# EMAIL_BACKEND = "django.core.mail.backends.filebased.EmailBackend"
# EMAIL_FILE_PATH = str(BASE_DIR.joinpath('sent_emails'))
# print(BASE_DIR)
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
# LEAFLET_CONFIG = {
# 'DEFAULT_CENTER': (47.019214, 5.855572),
# 'DEFAULT_ZOOM': 5,
# 'MAX_ZOOM': 20,
# 'MIN_ZOOM':3,
# 'SCALE': 'both',
# 'ATTRIBUTION_PREFIX': 'OrAG'
# }
TINYMCE_JS_URL = STATIC_URL + 'tinymce/tinymce.min.js'
TINYMCE_JS_ROOT = STATIC_ROOT + 'tinymce'
TINYMCE_DEFAULT_CONFIG = {
"height": "320px",
"width": "960px",
"menubar": "file edit view insert format tools table help",
"plugins": "advlist autolink lists link image charmap print preview anchor searchreplace visualblocks code "
"fullscreen insertdatetime media table paste code help wordcount spellchecker",
"toolbar": "undo redo | bold italic underline strikethrough | fontselect fontsizeselect formatselect | alignleft "
"aligncenter alignright alignjustify | outdent indent | numlist bullist checklist | forecolor "
"backcolor casechange permanentpen formatpainter removeformat | pagebreak | charmap emoticons | "
"fullscreen preview save print | insertfile image media pageembed template link anchor codesample | "
"a11ycheck ltr rtl | showcomments addcomment code",
"custom_undo_redo_levels": 10,
"language": "es_ES", # To force a specific language instead of the Django current language.
}
TINYMCE_COMPRESSOR = True
urls.py:
from django.contrib.gis import admin
from django.urls import include, path
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.utils.html import format_html
urlpatterns = [
path('admin/', admin.site.urls),
path('accounts/', include('django.contrib.auth.urls')),
path('notices/', include('notices.urls')),
path('_nested_admin/', include('nested_admin.urls')),
path('tinymce/', include('tinymce.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
And an extract of admin.py (imports and the only model class that will be updated through the admin. I skipped the whole file with Inlines and so on, let me know if it's needed):
class ObjetArchiAdmin(GeoModelAdminMixin, nested_admin.NestedModelAdmin):
formfield_overrides = {
models.TextField: {'widget': TinyMCE()}
}
list_display = ('titre', 'users', 'date', 'id')
fieldsets = (
('État-Civil', {
'fields': (('titre', 'date', 'users'), 'resume')
}),
('Provenance et attribution', {
'fields': ('point', ('prov_pays', 'prov_region'), ('prov_departement', 'prov_ville'), 'lieu_dit', 'attribution')
}),
('Conservation', {
'fields': (('cons_pays', 'cons_region'), ('cons_departement', 'cons_ville'),('cons_depot', 'cons_no_inventaire'), 'cons_localisation')
}),
('Description', {
'fields': ('description', 'contexte', 'observations_comp', ('materiau', 'stuc', 'polychromie'), 'hauteur_debut')
}),
('Analyse et Datation', {
'fields': ('analyse', 'inedit', 'ref_biblio', 'ref_biblio_2', ('date_chrono_debut', 'date_chrono_fin'), ('citeantique', 'provinceantique'))
})
)
list_filter = ('users__nom',)
search_fields = (
'id',
'titre',
'prov_pays__nom',
'prov_region__nom',
'prov_departement__nom',
'prov_ville__nom',
'cons_pays__nom',
'cons_region__nom',
'cons_departement__nom',
'cons_ville__nom',
'cons_depot',
'materiau__nom',
'provinceantique__nom',
'siteantique__nom',
'citeantique__nom'
)
autocomplete_fields = ('prov_pays', 'prov_region', 'prov_departement','prov_ville', 'cons_pays', 'cons_region', 'cons_departement', 'cons_ville', 'materiau', 'ensemble', 'provinceantique', 'citeantique', 'monument', 'cons_depot')
inlines = [OrnementInline, MoulureInline, ComposanteInline, IllusInline]
pnt = Point(5.855572,47.019214, srid=4326)
pnt.transform(900913)
default_lon, default_lat = pnt.coords
extra = 0
Here's what the admin looks like:
The TinyMCE editor should show up after "Résumé". The dimensions are actually good, according the settings, but the interface doesn't show up. I guess it can't find the static files but can't figure out what's wrong with my paths setup.
Thanks for your help!

new locale not redirecting properly

I have a basic django cms running with lots of localised content. I have been assigned to add few more languages before content can take over.
here is a sample english url:
<domain>/en/myhelp/
this is the sample menu which is supposed to render the menu dropdown:
<body>
{% cms_toolbar %}
<div class="container faq-main main-block">
<div class="select-wrapper">
<select name="language" id="faq-lang" class="lang-btn hide">
<option value="en">English</option>
<option value="hi">हिंदी</option>
<option value="mr">मराठी</option>
<option value="te">తెలుగు</option>
<option value="ta">தமிழ்</option>
<option value="kn">ಕನ್ನಡ</option>
<option value="bn">বাংলা</option>
<option value="ml">മലയാള൦</option>
<option value="gu">ગુજરાતી</option>
</select>
</div>
{% block content %}{% endblock content %}
{% block contact %}{% endblock contact %}
{% block actions %}{% endblock actions %}
</div>
{% render_bundle 'faq' 'js' %}
{% render_block "js" %}
</body>
any language selected from menu dropdown updates the url accordingly. for example on selecting mr, url mentioned above would change to:
<domain>/mr/myhelp/
All good so far.
Now i have added 2 more langs in this menu:
<option value="od">ଓଡିଆ</option>
<option value="as">অসমীয়া</option>
Problem is that when i select od / as from menu, url changes to:
<domain>/en/od/myhelp/
<domain>/en/as/myhelp/
basically, en is not removed from url locale causing page not found error. Any help or indication in right direction to correctly add this locale is appreciated.
version:
django-cms: 3.7.1
Django: 2.1
basic code:
urls.py
admin.autodiscover()
urlpatterns = [
url(r'^events/(?P<path>.*)$', EventsProxyView.as_view()),
url(r'^sitemap\.xml$', sitemap,
{'sitemaps': {'cmspages': CMSSitemap}}),
url(r'^healthcheck/$', healthcheck)
]
urlpatterns += i18n_patterns(
url(r'^admin/login', home),
url(r'^admin/', admin.site.urls), # NOQA
url(r'^', include('cms.urls')),
)
urlpatterns += [
url('', include('social_django.urls', namespace='social')),
]
relevant part from settings.xml
import os # isort:skip
from urllib.parse import urljoin
gettext = lambda s: s
DATA_DIR = os.path.dirname(os.path.dirname(__file__))
import os
from django.conf import global_settings
import django.conf.locale
# 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 = [
'*',
]
# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/
LANGUAGE_CODE = 'en'
TIME_ZONE = 'Asia/Kolkata'
USE_I18N = True
USE_L10N = True
USE_TZ = True
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'cms', 'templates'),],
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.i18n',
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.template.context_processors.media',
'django.template.context_processors.csrf',
'django.template.context_processors.tz',
'sekizai.context_processors.sekizai',
'django.template.context_processors.static',
'cms.context_processors.cms_settings',
],
'loaders': [
('django.template.loaders.cached.Loader', [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
])],
},
},
]
MIDDLEWARE = [
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.cache.UpdateCacheMiddleware',
'redirection.middleware.MyHelpRedirectMiddleware',
'djangocms_redirect.middleware.RedirectMiddleware',
'django.middleware.security.SecurityMiddleware',
'cms.middleware.HostsPrinterMiddleware',
'cms.middleware.DisableCSRF',
'cms.middleware.utils.ApphookReloadMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'cms.middleware.user.CurrentUserMiddleware',
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.toolbar.ToolbarMiddleware',
'cms.middleware.language.LanguageCookieMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware',
]
WEBPACK_LOADER = {
'DEFAULT': {
'BUNDLE_DIR_NAME': 'bundles/',
'STATS_FILE': os.path.join(BASE_DIR, 'cms', 'scripts', 'dist', 'bundles', 'webpack-stats.json'),
}
}
INSTALLED_APPS = [
'djangocms_admin_style',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.admin',
'django.contrib.sites',
'django.contrib.sitemaps',
'django.contrib.staticfiles',
'django.contrib.messages',
'cms',
'menus',
'sekizai',
'treebeard',
'djangocms_text_ckeditor',
'filer',
'easy_thumbnails',
'djangocms_column',
'djangocms_file',
'djangocms_link',
'djangocms_picture',
'djangocms_style',
'djangocms_snippet',
'djangocms_googlemap',
'djangocms_video',
'social_django',
'revproxy',
'djangocms_redirect',
'redirection',
'webpack_loader',
'django_select2',
'accordion'
]
LANGUAGES = (
## Customize this
('en', gettext('en')),
('hi', gettext('hi')),
('mr', gettext('mr')),
('te', gettext('te')),
('ta', gettext('ta')),
('kn', gettext('kn')),
('gu', gettext('gu')),
('bn', gettext('bn')),
('ml', gettext('ml')),
('as', gettext('as')),
('od', gettext('od'))
)
CMS_LANGUAGES = {
## Customize this
1: [
{
'code': 'en',
'name': gettext('en'),
'redirect_on_fallback': True,
'public': True,
'hide_untranslated': False,
},
{
'code': 'hi',
'name': gettext('hi'),
'public': True,
'fallbacks': ['en'],
},
{
'code': 'mr',
'name': gettext('mr'),
'public': True,
'fallbacks': ['en'],
},
{
'code': 'te',
'name': gettext('te'),
'public': True,
'fallbacks': ['en'],
},
{
'code': 'ta',
'name': gettext('ta'),
'public': True,
'fallbacks': ['en'],
},
{
'code': 'kn',
'name': gettext('kn'),
'public': True,
'fallbacks': ['en'],
},
{
'code': 'gu',
'name': gettext('gu'),
'public': True,
'fallbacks': ['en'],
},
{
'code': 'bn',
'name': gettext('bn'),
'public': True,
'fallbacks': ['en'],
},
{
'code': 'ml',
'name': gettext('ml'),
'public': True,
'fallbacks': ['en'],
},
{
'code': 'od',
'name': gettext('od'),
'public': True,
'fallbacks': ['en'],
},
{
'code': 'as',
'name': gettext('as'),
'public': True,
'fallbacks': ['en'],
}
],
'default': {
'fallbacks': ['en', 'hi'],
'redirect_on_fallback': True,
'public': True,
'hide_untranslated': False,
},
}
CMS_TEMPLATES = (
## Customize this
('fullwidth.html', 'Fullwidth'),
('faq_fullwidth.html', 'FAQ Fullwidth'),
('faq_article.html', 'FAQ Article'),
('faq_article_with_feedback.html', 'FAQ Article with Feedback'),
)
CMS_PERMISSION = True
CMS_PLACEHOLDER_CONF = {}
MIGRATION_MODULES = {
}
THUMBNAIL_PROCESSORS = (
'easy_thumbnails.processors.colorspace',
'easy_thumbnails.processors.autocrop',
'filer.thumbnail_processors.scale_and_crop_with_subject_location',
'easy_thumbnails.processors.filters'
)
CMS_MYHELP_REDIRECT_USE_REQUEST = True
CMS_MYHELP_REDIRECT_ALLOWED_PATHS = {
'/myhelp',
'/myhelp/',
'/en/myhelp',
'/en/myhelp/',
}

How can I open Django app page within the domain name, not like domain/app_page_url?

Python == 3.6.5
Django == 1.8
Recently purchased domain name, http://www.favourite.uz. And placed my Django project to my hosting in cPanel. When I browse domain http://www.favourite.uz, it throws to default page of cPanel. But when try http://www.favourite.uz/news it opens my django app. I wanted to browse this http://www.favourite.uz/news page within the domain name, without /news.
I placed used server's namespaces in Domain registrator's page. Tried to create another simple project from this tutorial,https://www.youtube.com/watch?v=ffqMZ5IcmSY. But it still opens default page of cPanel.
Main favourite/urls.py
# from django.urls import path
from django.conf.urls import include, url
from django.conf import settings
from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.views.static import serve
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^news/', include('news.urls')),
url(r'^i18n/', include('django.conf.urls.i18n')),
]
if settings.DEBUG is False:
urlpatterns += [
url(r'^media/(?P<path>.*)$', serve, {
'document_root' : settings.MEDIA_ROOT,}),
]
(news)app url, news/urls.py
from . import views
urlpatterns =[
url(r'^$', views.NewsView.as_view(), name='posts'),
url(r'^i18n/', include('django.conf.urls.i18n')),
url(r'^index', views.search, name="search"),
url(r'^chaining/', include('smart_selects.urls')),
url(r'^league/(?P<pk>[0-9]+)/$', views.league_detail, name='league_detail'),
]
settings, favourite/settings.py
Django settings for futbik_version_7 project.
Generated by 'django-admin startproject' using Django 2.0.5.
For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""
import os
from django.utils.translation import ugettext_lazy as _
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = "/media/"
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
STATIC_URL = '/static/'
STATIC_ROOT = 'news/static/'
STATICFILES_DIRS =(
os.path.join(BASE_DIR,'news/static/images'),
)
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'az=5ur80-1ge#!951w3(bxaqg1zwo1+a#6+*s*dw(sgkywhb3z'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = ['127.0.0.1', 'localhost', 'www.favourite.uz', 'favourite.uz']
# Application definition
INSTALLED_APPS = [
'modeltranslation',
'news.apps.NewsConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_userforeignkey',
'simplesearch',
'smart_selects',
]
MIDDLEWARE_CLASSES = [
'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_userforeignkey.middleware.UserForeignKeyMiddleware',
'django.middleware.locale.LocaleMiddleware',
]
LANGUAGES = (
('en', _('Uzbek')),
('ru', _('Русский')),
)
LOCALE_PATHS = (
os.path.join(BASE_DIR, 'locale'),
)
# MODELTRANSLATION_DEFAULT_LANGUAGE = 'en'
# MODELTRANSLATION_TRANSLATION_REGISTRY = 'news.translation'
ROOT_URLCONF = 'futbik_version_7.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
# os.path.join(BASE_DIR, 'news/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',
'news.context_processors.add_variable_to_context',
],
},
},
]
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.i18n',
)
WSGI_APPLICATION = 'futbik_version_7.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'),
}
}
# SOUTH_DATABASE_ADAPTERS = {
# 'default': 'south.db.sqlite3'
# }
# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
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',
},
]
# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/
LANGUAGE_CODE = 'en'
TIME_ZONE = 'Asia/Tashkent'
USE_I18N = True
USE_L10N = True
USE_TZ = True
USE_DJANGO_JQUERY = False
# MODELTRANSLATION_DEBUG = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/
I really appreciate, if someone encountered such situation and helps me to solve this little problem.
P.s. I am beginner in Django!
Try adding a redirect URL to your urls, so that / redirects to /news. In favourite/urls.py, add this:
from django.views.generic import RedirectView
url_patterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^news/', include('news.urls')),
url(r'^i18n/', include('django.conf.urls.i18n')),
url(r'^$', RedirectView.as_view(pattern_name='posts', permanent=True)) # <—- add this line
]
This should work.
I just find it strange that instead of showing a 404 not found, cPanel seems to hijack the missing page. If my method doesn't work, you should contact cPanel support and ask how to enable the default domain to be routed to your app.