Django 管理站点重命名 URL 以匹配我的语言
我想自定义管理站点的 URL,以便它们以我的母语(西班牙语)显示。我想要的是使用 /nuevo 而不是 /add 等。这可能吗?
I would like to customize the URLs for the admin site so they appear in my native language (Spanish). What I want is to use /nuevo instead of /add and so on. Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想这会做你想做的。 ModelAdmin.get_urls()
但问题是,如何将新的 url 连接到
admin
视图?默认的 get_urls() 位于 django/contrib/admin/options.py 中,它有一些有点复杂的代码来生成默认的 url。
请注意,我将
%s_%s_add
保留为英语。您可以包装此函数,这样您就不必在每个 ModelAdmin 类中包含整个函数。
编辑
该代码使用了一个名为
update_wrapper
的函数,该函数的导入方式如下:我以前没有见过这个函数,而且我怀疑很多人都见过,所以我认为指出导入会很有用。
, wrap(self.changelist_view), name='%s_%s_changelist' % info), url(r'^add/我要做的就是在每个
ModelAdmin
中使用此函数,但将 url 文本更改为您的语言等效项。在您的示例中,
add/
如下所示:请注意,我将
%s_%s_add
保留为英语。您可以包装此函数,这样您就不必在每个 ModelAdmin 类中包含整个函数。
编辑
该代码使用了一个名为
update_wrapper
的函数,该函数的导入方式如下:我以前没有见过这个函数,而且我怀疑很多人都见过,所以我认为指出导入会很有用。
, wrap(self.add_view), name='%s_%s_add' % info), url(r'^(.+)/history/我要做的就是在每个
ModelAdmin
中使用此函数,但将 url 文本更改为您的语言等效项。在您的示例中,
add/
如下所示:请注意,我将
%s_%s_add
保留为英语。您可以包装此函数,这样您就不必在每个 ModelAdmin 类中包含整个函数。
编辑
该代码使用了一个名为
update_wrapper
的函数,该函数的导入方式如下:我以前没有见过这个函数,而且我怀疑很多人都见过,所以我认为指出导入会很有用。
, wrap(self.history_view), name='%s_%s_history' % info), url(r'^(.+)/delete/我要做的就是在每个
ModelAdmin
中使用此函数,但将 url 文本更改为您的语言等效项。在您的示例中,
add/
如下所示:请注意,我将
%s_%s_add
保留为英语。您可以包装此函数,这样您就不必在每个 ModelAdmin 类中包含整个函数。
编辑
该代码使用了一个名为
update_wrapper
的函数,该函数的导入方式如下:我以前没有见过这个函数,而且我怀疑很多人都见过,所以我认为指出导入会很有用。
, wrap(self.delete_view), name='%s_%s_delete' % info), url(r'^(.+)/我要做的就是在每个
ModelAdmin
中使用此函数,但将 url 文本更改为您的语言等效项。在您的示例中,
add/
如下所示:请注意,我将
%s_%s_add
保留为英语。您可以包装此函数,这样您就不必在每个 ModelAdmin 类中包含整个函数。
编辑
该代码使用了一个名为
update_wrapper
的函数,该函数的导入方式如下:我以前没有见过这个函数,而且我怀疑很多人都见过,所以我认为指出导入会很有用。
, wrap(self.change_view), name='%s_%s_change' % info), ) return urlpatterns我要做的就是在每个
ModelAdmin
中使用此函数,但将 url 文本更改为您的语言等效项。在您的示例中,
add/
如下所示:请注意,我将
%s_%s_add
保留为英语。您可以包装此函数,这样您就不必在每个 ModelAdmin 类中包含整个函数。
编辑
该代码使用了一个名为
update_wrapper
的函数,该函数的导入方式如下:我以前没有见过这个函数,而且我怀疑很多人都见过,所以我认为指出导入会很有用。
I think this is will do what you want. ModelAdmin.get_urls()
But the problem is going to be, how do you hook up the new url to the
admin
view?The default
get_urls()
is indjango/contrib/admin/options.py
, and it has some somewhat complex code to generate the default urls.Note that I left
%s_%s_add
in English.You can probably wrap this function so you don't have to include the entire thing in each ModelAdmin class.
Edit
That code uses a function named
update_wrapper
which is imported like this:I hadn't seen this function before, and I doubt many people have so I thought it'd be useful to point out the import.
, wrap(self.changelist_view), name='%s_%s_changelist' % info), url(r'^add/What I would do is use this function in each of your
ModelAdmin
s, but change the url text to your language equivalent.In your example,
add/
would look like this:Note that I left
%s_%s_add
in English.You can probably wrap this function so you don't have to include the entire thing in each ModelAdmin class.
Edit
That code uses a function named
update_wrapper
which is imported like this:I hadn't seen this function before, and I doubt many people have so I thought it'd be useful to point out the import.
, wrap(self.add_view), name='%s_%s_add' % info), url(r'^(.+)/history/What I would do is use this function in each of your
ModelAdmin
s, but change the url text to your language equivalent.In your example,
add/
would look like this:Note that I left
%s_%s_add
in English.You can probably wrap this function so you don't have to include the entire thing in each ModelAdmin class.
Edit
That code uses a function named
update_wrapper
which is imported like this:I hadn't seen this function before, and I doubt many people have so I thought it'd be useful to point out the import.
, wrap(self.history_view), name='%s_%s_history' % info), url(r'^(.+)/delete/What I would do is use this function in each of your
ModelAdmin
s, but change the url text to your language equivalent.In your example,
add/
would look like this:Note that I left
%s_%s_add
in English.You can probably wrap this function so you don't have to include the entire thing in each ModelAdmin class.
Edit
That code uses a function named
update_wrapper
which is imported like this:I hadn't seen this function before, and I doubt many people have so I thought it'd be useful to point out the import.
, wrap(self.delete_view), name='%s_%s_delete' % info), url(r'^(.+)/What I would do is use this function in each of your
ModelAdmin
s, but change the url text to your language equivalent.In your example,
add/
would look like this:Note that I left
%s_%s_add
in English.You can probably wrap this function so you don't have to include the entire thing in each ModelAdmin class.
Edit
That code uses a function named
update_wrapper
which is imported like this:I hadn't seen this function before, and I doubt many people have so I thought it'd be useful to point out the import.
, wrap(self.change_view), name='%s_%s_change' % info), ) return urlpatternsWhat I would do is use this function in each of your
ModelAdmin
s, but change the url text to your language equivalent.In your example,
add/
would look like this:Note that I left
%s_%s_add
in English.You can probably wrap this function so you don't have to include the entire thing in each ModelAdmin class.
Edit
That code uses a function named
update_wrapper
which is imported like this:I hadn't seen this function before, and I doubt many people have so I thought it'd be useful to point out the import.