Trying my hands on Django. TIME_ZONEat admin module shows different than the local time. I would like to edit the time according to the current time. Which Django file should I edit to synchronize the time?
I tried the documentation on official Django website but did not help me out.
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
```
On your settings.py, add a TIME_ZONE config:
E.G:
TIME_ZONE = "UTC"
or
TIME_ZONE = "America/Boise"
Plus, enable USE_TZ:
USE_TZ = True
You can read more here
Related
I'm trying to add multi language support for a django project using Django i18n official documentaion:
https://docs.djangoproject.com/en/4.1/topics/i18n/translation/
When I change the LANGUAGE_CODE to something like 'fa', by default the admin panel changes to RTL.
But the problem is when I use other RTL languages like 'ku' (kurdish) the page remains in ltr.
I know we can change the css manualy, but wonder what is the problem here and how some languages like Arabic or persian does the RTL part automaticaly but others dont.
Thanks in advance
# settings.py
LANGUAGE_CODE = 'en-us'
USE_I18N = True
USE_L10N = True
TIME_ZONE = 'UTC'
USE_TZ = True
LANGUAGES = (
('en', _('English')),
('ku', _('Kurdish')),
('fa', _('Persian')),
)
LOCALE_PATHS = [
Path(BASE_DIR, 'django_i18n', 'locale'),
]
# url.py
urlpatterns = i18n_patterns(
path('admin/', admin.site.urls),
) +static(settings.MEDIA_URL, document_root= settings.MEDIA_ROOT)
just found the answer here:
https://github.com/django/django/blob/main/django/conf/global_settings.py#L158
So all I had to do was add this to setting.py:
LANGUAGES_BIDI = ["ku",]
here is a question i can use django time zone for utc and it worked fine
but when i switch the default time zone to 'Asia/Tehran' it wont work and i get the error
ValueError: Incorrect timezone setting: ASIA/TEHRAN
the actual code in settings.py is:
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Tehran'
USE_I18N = True
USE_L10N = True
USE_TZ = True
and it is on django time zone list i checked it
the system is ubuntu 20 and django version is 3.2
try this
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC+3:30'
USE_I18N = True
USE_L10N = True
USE_TZ = True
hi I'm testing my Django rest framework project on a hosting server. when I open the my site domain my site is without any default django style. my admin panel is just html it doesn't have django admin panel style. I connected to the project on host and when i type the collect static command I have this error:
django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.
this is the admin panel:
first page:
and this is my project settings.py:
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Tehran'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# ckeditor
CKEDITOR_BASEPATH = "/static/ckeditor/ckeditor/"
CKEDITOR_UPLOAD_PATH = "uploads/"
There are two working versions of the translation on the site - Russian and English using i18n. How to make sure that everyone has a website loaded in Russian and then, at the request of the user, he can change it to English?
MIDDLEWARE = [
...
'django.middleware.locale.LocaleMiddleware',
...
]
LANGUAGE_CODE = 'ru'
LANGUAGES = (
('ru', _('Russian')),
('en', _('English')),
)
LOCALE_PATHS = (
os.path.join(BASE_DIR, 'locale'),
)
TIME_ZONE = 'Europe/Kiev'
USE_I18N = True
USE_L10N = True
USE_TZ = True
I've already translated my project in Malagasy (mg_Mg) but when installing django-allauth and override templates, translation won't be applied.
After python manage.py makemessages, python manage.py compilemessages and testing some translations eg: sign up -> Hisoratra anarana in render it show sign up.
But in my local app, all templates are translated correctly.
In config/setting.py
import environ
BASE_DIR = environ.Path(__file__) - 2
...
# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
LANGUAGES = [
('en-us', 'English'),
('fr-fr', 'French'),
('mg-mg', 'Malagasy'),
]
LOCALE_PATHS = [BASE_DIR('locale')]
In fandaharana/views.py
def month(request, month_num, year_num):
translation.activate('mg-mg')
...
return render(request, 'month.html', data)