The following plug-and-play piece of code works perfectly since Django
1.7
. All you have to do is copy the below code in the __init__.py
file
of the specific app and change the VERBOSE_APP_NAME
parameter.
from os import path
from django.apps import AppConfig
VERBOSE_APP_NAME = "YOUR VERBOSE APP NAME HERE"
def get_current_app_name(file):
return path.dirname(file).replace('\\', '/').split('/')[-1]
class AppVerboseNameConfig(AppConfig):
name = get_current_app_name(__file__)
verbose_name = VERBOSE_APP_NAME
default_app_config = get_current_app_name(__file__) + '.__init__.AppVerboseNameConfig'
If you use this for multiple apps, you should factor out the get_current_app_name
function
to a helper file.
修改前
修改后:
如果修改为中文,则VERBOSE_NAME = u'中文名称',否则会执行不通过。