【问题标题】:join() argument must be str, bytes, or os.PathLike object, not 'function' problemjoin() 参数必须是 str、bytes 或 os.PathLike 对象,而不是“函数”问题
【发布时间】:2020-09-28 14:56:10
【问题描述】:

我目前正在开发我的第一个网站,但我遇到了一些问题,例如:

join() 参数必须是 str、bytes 或 os.PathLike 对象,而不是“函数”。

我认为它与views.py有关,但我真的不知道如何解决它。

代码如下:

def translator_view(request):

    def translator(phrase):
        translation = ""
        for letter in phrase:
            if letter.lower() in "a":
                if letter.isupper:
                    translation = translation + "U"
                else:
                    translation = translation + "u"
            elif letter.lower() in "t":
                if letter.isupper:
                    translation = translation + "A"
                else:
                    translation = translation + "a"
            elif letter.lower() in "c":
                if letter.isupper:
                    translation = translation + "G"
                else:
                    translation = translation + "g"
            elif letter.lower() in "g":
                if letter.isupper:
                    translation = translation + "C"
                else:
                    translation = translation + "c"
        return translation
    return render(request, translator, 'main/translator.html')

【问题讨论】:

  • 我认为您应该尽力提供Minimal, Reproducible Example 和更明确的错误消息。
  • 完整的错误信息是什么?它在哪条线上?我在文本中没有看到单个 .join,所以它一定在您正在使用的某个库函数中。
  • 我认为问题在于将两个函数放在一起

标签: python django


【解决方案1】:

您可能需要检查您的代码。特别是“isupper”部分没有括号。

应该是:

if letter.isupper():

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-24
    • 2020-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多