Django - Accessing request META data from production

混江龙づ霸主 提交于 2020-01-05 04:15:13

问题


I'm trying to send a list of datetimes to the client by JSON formatted as its locale.

So the main issue is actually trying to get the locale of the client.

I tried to use request.META['LC_TIME'] (which seems to be the client's prefered locale for dates and times)

This key is here in development but not in production.

KeyError: 'LC_TIME'

How can it be explained ? Am I on the right track ?


回答1:


First, let's determine what you mean under 'Production environment'. Under DEV environment, the browser connects directly to the Django web server, and all HTTP headers are sent directly to it. In PRODUCTION, you usually have a proxy. This could be an nginx or other similar software. Their main purpose is to redirect, while performing some checks. You should check in your PRODUCTION environment, what is the actual setup of the proxy(if any), and if it strips any HTTP header sent from client(which seems like a valid reason for the error you get).

Besides the configuration issues, it is recommended to use a default value:

user_lc_time = request.META.get('LC_TIME', default_lc_time)


来源:https://stackoverflow.com/questions/10802680/django-accessing-request-meta-data-from-production

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!