服务器没有i18n文件,django生产服务器i18n网址没有重定向?(django production server i18n urls not redirecting?)...

django生产服务器i18n网址没有重定向?(django production server i18n urls not redirecting?)

在我的本地服务器上,当我通过键入127.0.0.1:8000进入主页时,它会自动将我推到/ en /,就像我想要的那样。

在我的生产服务器上,它使我陷入'/',这给了我一个404错误。 奇怪的是,我在我的404页面中点击的任何链接仍然有网站标题将带我到/ en / url,然后一切工作正常。

我在这里错过了什么吗? 为什么它不自动重定向我?

编辑:忘了添加代码...

from django.conf.urls.i18n import i18n_patterns

urlpatterns += i18n_patterns(

url(r'^accounts/', include('allauth.urls')),

url(r'^forum/', include('djangobb_forum.urls', namespace='djangobb')),

url(r'^blog/', include('blog.urls', namespace='blog')),

url(r'^', include('main.urls')),

)

编辑:半解决....

好吧,经过多次试验和错误,我发现它来自自定义的404和500模板,我不知道为什么,我真的很想尝试并保留我的自定义模板...任何想法?

On my local server, when I go to the homepage by typing 127.0.0.1:8000 it automatically pushes me to /en/ like I want it to.

On my production server it drops me in '/' which gives me a 404 error. Oddly enough any of the link i click on in my 404 page which still has the site header will take me to the /en/ urls and then everything works fine.

Did I miss something here? Why isn't it redirecting me automatically?

EDIT: forgot to add the code...

from django.conf.urls.i18n import i18n_patterns

urlpatterns += i18n_patterns(

url(r'^accounts/', include('allauth.urls')),

url(r'^forum/', include('djangobb_forum.urls', namespace='djangobb')),

url(r'^blog/', include('blog.urls', namespace='blog')),

url(r'^', include('main.urls')),

)

EDIT: semi solved....

ok so after much trial and error I found that it was coming from having custom 404 and 500 templates, I have no clue why and I would really like to try and keep my custom templates... Any ideas?

原文:https://stackoverflow.com/questions/34769454

更新时间:2020-03-03 19:04

最满意答案

这是文档说要添加到urls.py的自定义404和500处理程序行。 我想如果我想在404和500之后通过自定义模板做一些特殊行为,我只需要这些。 我拿出urls.py中的视图和处理程序,并将模板文件夹中的404.html和500.html模板保留下来,一切正常,因为我希望它...

It was the custom 404 and 500 handler lines that the docs say to add to urls.py. I think I only needed these if I wanted some special behavior on a 404 and 500 past a custom template. I took out the views and the handlers in urls.py and left the 404.html and 500.html templates in the templates folder and everything works as I would want it to...

相关问答

我不会推荐任何人在PHP中使用setlocale()和gettext()进行本地化 (有一些严重的问题会驱动任何开发人员)。 但无论如何,没有en_EN语言环境。 下划线之前的标识符是语言(en =英文),下划线之后的标识符是国家(EN = ???)。 你可能应该使用en_US,en_GB或其他东西。 I wouldn't recommend anyone using setlocale() and gettext() for localization in PHP (there are some

...

我认为'packages'键是指js_info_dict中的那个。 在错误中它实际上引用了名为packages的捕获正则表达式组。 不需要动态packages变量,因为我在js_info_dict指定了一个静态包my_app ,因此要使用的正确url模式是: url(r'^jsi18n/$', javascript_catalog, js_info_dict, name='javascript_catalog'),

I thought the 'packages' key referred to

...

你应该跑步 django-admin.py makemessages -d djangojs -l en

django-admin.py compilemessages

为你的每种语言:) you should run django-admin.py makemessages -d djangojs -l en

django-admin.py compilemessages

for each language you have :)

我找不到与此相关的任何其他问题或评论。 我决定复制rails-i18n gem的fr.yml哈希。 我没有必要在我的开发服务器上执行此操作以将日期格式转换为法语。 正如我所说,没有它们,它工作正常。 当我在生产中部署新的yaml文件时,我的所有子句都是法语。 我想在i18n过程的某个地方有一个大海捞针类型的针。 至少日期的Rails翻译现在正在运行。 I could not find any other questions or comments relating to this. I decid

...

这是LOCALE_PATHS ,而不是LOCAL( 链接 )。 It's LOCALE_PATHS, not LOCAL (link).

实质上,你遇到了旧版CORS标准中的一个错误。 原始标准基本上使得在使用prelight请求时无法执行本地重定向。 关于这个问题看到这个问题 ,以及关于获取标准的这个错误报告 。 在你的情况下, USE_I18N = True会发生这种情况,因为该设置是触发重定向的原因。 希望这个修复很快将被浏览器实现。 (根据关于Fetch bug的最新报告 ,它已经在Edge中运行)。与此同时, 这个答案提出了一些解决方法。 In essence, you're running into a bug in a

...

你必须安装gettext包。 对于Windows,您可以从GetText for Windows下载 如果你使用的是CentOS那么运行命令yum install gettext ,对于Ubuntu用户,命令是sudo apt-get install -y gettext You have to install gettext package. For windows you can download from GetText for Windows If you are using CentOS

...

正如你正在使用django 1.8检查这个答案 。 如果你可以升级到Django的当前版本(至少1.10),你会得到本地支持,检查文档 。 As you are using django 1.8 check out this answer. If you can upgrade to django current version (or 1.10 at least) you'll get native support, check the docs.

答案如下: 将DEBUG设置为i18n的错误更改行为 这里的问题是,您的模板文件夹中可能没有404.html,因此当DEBUG为False时,代码路径生成服务器错误(500)。 您可能在服务器的日志中看到了适当的消息。 使用这个404.html模板来检查: {% extends "base.html" %}

{% block title %}Page not found{% endblock %}

{% block content %}

Page not found

...

这是文档说要添加到urls.py的自定义404和500处理程序行。 我想如果我想在404和500之后通过自定义模板做一些特殊行为,我只需要这些。 我拿出urls.py中的视图和处理程序,并将模板文件夹中的404.html和500.html模板保留下来,一切正常,因为我希望它... It was the custom 404 and 500 handler lines that the docs say to add to urls.py. I think I only needed these i

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值