简体   繁体   English

地址 Django 区分大小写

[英]Address case sensitivity in Django

Let's say I have an app named TaskDashboard .假设我有一个名为TaskDashboard的应用程序。 Yes, I know that the best practice is to give names for packages in lower case.是的,我知道最佳做法是以小写字母命名包。 But let's say that I can't change that.但是假设我无法改变它。

Then I want to generate some docs using the built-in Django mechanisms.然后我想使用内置的 Django 机制生成一些文档。 I wrote the following docstring for a model:我为 model 编写了以下文档字符串:

class Task(models.Model):
    """
    Every task is linked to a :model:`TaskDashboard.Column`.
    """

That allows to form the links to related models in the documentation.这允许形成文档中相关模型的链接。 However, when I click on that, I get to the lower cased address /.../taskdashboard.column and get 404 error.但是,当我单击它时,我会到达小写地址/.../taskdashboard.column并收到 404 错误。 If I change the address to /.../TaskDashboard.column/ I get the proper page.如果我将地址更改为/.../TaskDashboard.column/我会得到正确的页面。

How to solve the problem with case sensitivity without changing the app name?如何在不更改应用名称的情况下解决区分大小写的问题?

Change AppConfig.label in app config在应用配置中更改AppConfig.label

#TaskDashboard/apps.py
from django.apps import AppConfig


class TaskdashboardConfig(AppConfig):
    name = 'TaskDashboard'
    label = 'taskdashboard'

and specify this new config class in INSTALLED_APPS并在INSTALLED_APPS中指定这个新配置 class

INSTALLED_APPS = [
    # other apps
    'TaskDashboard.apps.TaskdashboardConfig',
    # other apps
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM