【问题标题】:TypeError at /uploaddd/ uploaddd() takes 0 positional arguments but 1 was given/uploaddd/uploaddd() 处的 TypeError 采用 0 个位置参数,但给出了 1 个
【发布时间】:2020-07-23 11:13:40
【问题描述】:

当我尝试仅打印 JSON 时出现以下错误

我的 urls.py 中有以下内容

from search import views as search_views


urlpatterns = [
    url(r'^uploaddd', search_views.uploaddd, name='upload'),

]

在我的 search/views.py 目录中,我有以下内容

def uploaddd():
    documents = {
        {
        "@search.action": "upload",
        "HotelId": "1",
        "HotelName": "Secret Point Motel 2020",
        "Description": "The hotel is ideally located on the main commercial artery of the city in the heart of New York. A few minutes away is Time's Square and the historic centre of the city, as well as other places of interest that make New York one of America's most attractive and cosmopolitan cities.",
        "Description_fr": "L'hôtel est idéalement situé sur la principale artère commerciale de la ville en plein cœur de New York. A quelques minutes se trouve la place du temps et le centre historique de la ville, ainsi que d'autres lieux d'intérêt qui font de New York l'une des villes les plus attractives et cosmopolites de l'Amérique.",
        "Category": "Boutique",
        "Tags": [ "pool", "air conditioning", "concierge" ],
        "ParkingIncluded": "false",
        "LastRenovationDate": "1970-01-18T00:00:00Z",
        "Rating": 3.60,
        "Address": {
            "StreetAddress": "677 5th Ave",
            "City": "New York",
            "StateProvince": "NY",
            "PostalCode": "10022",
            "Country": "USA"
            }
        },
    
    }    
    return JsonResponse({'doc': documents })

我收到以下错误

/uploaddd/ 处的类型错误 uploaddd() 接受 0 个位置参数,但给出了 1 个

【问题讨论】:

    标签: python django wagtail


    【解决方案1】:

    视图函数被传递一个请求对象,所以你的函数定义需要被写成接收它作为一个参数:

    def uploaddd(request):
    

    【讨论】:

      猜你喜欢
      • 2021-01-16
      • 1970-01-01
      • 1970-01-01
      • 2023-01-11
      • 2020-06-13
      • 2021-06-28
      • 1970-01-01
      • 1970-01-01
      • 2018-12-29
      相关资源
      最近更新 更多