介绍
我对localeURL用法有疑问.对于我来说,一切都很棒,如下所示:http: //www.example.com/
如果我在地址栏中键入 http://www.example.com/,则会在http://www.example.com/ en /中正确转到.
如果我使用视图change_locale,它也可以(即更改www.example.com/ en/in www.example.com/ fr /).
问题
但我的应用程序使用apache作为服务器,使用mod_wsgi.httpd.conf脚本包含以下行:
WSGIScriptAlias /MY_PREFIX /path/to/django/app/apache/django.wsgi
Run Code Online (Sandbox Code Playgroud)
给出这样的网址:http:
//www.example.com/MY_PREFIX/
change_locale视图出现了同样的问题.我修改了这段代码以便管理这个前缀(存储在settings.SERVER_PREFIX中):
def change_locale(request) :
"""
Redirect to a given url while changing the locale in the path
The url and the locale code need to be specified in the
request parameters.
O. Rochaix; Taken from localeURL view, and tuned to manage :
- SERVER_PREFIX …Run Code Online (Sandbox Code Playgroud)