Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python django决定基于用户ip的语言模板_Python_Django - Fatal编程技术网

Python django决定基于用户ip的语言模板

Python django决定基于用户ip的语言模板,python,django,Python,Django,在my views.py中,我有不同的语言模板要显示。 我想根据用户第一次进入时的ip决定这一点, 我该怎么做? 我应该用谷歌搜索哪些关键词? 请引导我,非常感谢 views.py def index(request): if request.GET.get("lan", None): lan = request.GET['lan'] if lan == 'en': return render(request, 'english/i

在my views.py中,我有不同的语言模板要显示。
我想根据用户第一次进入时的ip决定这一点,
我该怎么做? 我应该用谷歌搜索哪些关键词?
请引导我,非常感谢

views.py

def index(request):
    if request.GET.get("lan", None):
        lan = request.GET['lan']
        if lan == 'en':
            return render(request, 'english/index.html',)
    return render(request, 'chinese/index.html',)
在我的模板/chinese/index.html中:

 <a href="{% url 'core:index' %}?lan=en">

使用GeoIP数据库和任何提供绑定的python模块。 一些好的建议是:


那么您想获取用户ip的位置(国家/地区)?不,您不应该尝试这样做。您希望IP如何与所需语言相关联?想想语言高度混杂的国家。如果用户只是访问另一个国家怎么办?你应该使用确定语言的标准方法,即
接受语言
标题。你能给我提供一个网站或互联网上的教程吗?我还不了解,请尝试使用