【问题标题】:Documenting Django using UML使用 UML 记录 Django
【发布时间】:2020-04-29 15:23:35
【问题描述】:

你好堆栈溢出社区

我正在尝试记录我的项目,并且在如何将 Django 视图转换为 UML 类图方面已经加倍努力。

我不得不提一下,我没有使用类视图,只是普通视图。

你能告诉我这样好吗?我是否需要让读者知道我想要达到的目标,或者图表的内容很清楚?

非常感谢您的反馈

这是代码

def index_crypto(request):

    import requests
    import json

    #Api Call
    url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest?start=1'
    headers = {'Accepts': 'application/json','X-CMC_PRO_API_KEY':'xxxxxxxxxx',}
    params = {'convert' :'USD'}
    api_request = requests.get(url, headers= headers,params= params) #Request Object

    try:
        data = json.loads(api_request.content) #JSON file containing data.

    except Exception as e:

            data = "Error...."
            print(e)

    api_assets= [] 

    for i in data["data"]:
        api_assets.append(i)

    return render(request,'index_crypto.html',{'api_assets': api_assets})

【问题讨论】:

    标签: django uml


    【解决方案1】:

    通过将 index_crypto 定义为类中的操作,您将与 UML 完全兼容。

    因为 url、headersparams 有一个常量值并且只在 index_crypto 中可见,你可以将它们声明为 read- only ({readOnly}) static 属性(名称带下划线)具有可见性 private 而不是 public

    对于 api_requestRequest 在你的图表中?)不清楚使用属性,它是一个纯粹的局部工作变量,就像我们在操作中一样,更好帮我删除它。

    如果我没记错 index_crypto 返回一个 HttpResponse

    【讨论】:

    • @caff_91 一个只读属性在type后面用{readOnly}表示,我错说没有特殊符号
    • 谢谢!我只是检查了一下,确实 {readOnly} 去了那里。感谢您的澄清。
    猜你喜欢
    • 2021-11-07
    • 1970-01-01
    • 2012-04-07
    • 1970-01-01
    • 2022-01-01
    • 2013-11-29
    • 2017-10-04
    • 1970-01-01
    • 2019-04-09
    相关资源
    最近更新 更多