仅在生产服务器上发生此问题。设置中的语言如下所示:
`LANGUAGE_CODE = 'pl'
LANGUAGES = [
('pl', gettext('PL')),
('en', gettext('EN')),
]`
@register.simple_tag(takes_context=True)
def unsubscribe_link(context, href):
domain = 'http://' + Site.objects.get_current().domain
a = '<a href="%s" target="_self">%s</a>'
if context.get('preview'):
return a % ('#', href)
return a % (domain + context['participant'].get_unsubscribe_url(), href)
models.participant:
@models.permalink
def get_unsubscribe_url(self):
return ('participant-unsubscribe', [self.pk, self.unsubscribe_hash])
问题是unsubscribe_link templatetag以格式返回url:domain / en-us / xxx / xxx,显然url响应是404.如果我将“en-us”改为“pl”,一切正常。我找不到这个问题的根源。本地网址正确生成。
答案 0 :(得分:1)
我认为您的问题与cronjob区域设置有关:
您可以创建(如果尚未存在)文件/ etc / environment并添加以下行:
LANG=pl_PL.UTF-8
更改命令:
class Command(BaseCommand):
can_import_settings = True
def handle(self, *args, **options):
# Activate a fixed locale, e.g. Polish
translation.activate('pl')
# Or you can activate the LANGUAGE_CODE # chosen in the settings:
#
#from django.conf import settings
#translation.activate(settings.LANGUAGE_CODE)
# Your command logic here
# ...
translation.deactivate()