Django 报错 TypeError: xxx() got multiple values for argument 'xxx'

yufei       5 年 前       1579

这个错误常见于定义视图函数,也就是 views 中的相应的请求的处理函数

一般情况下,我们会直接在视图函数中定义路径参数,比如下面这个

from django.shortcuts import render
from django.http import HttpResponse

# Create your views here.
def gen_qrcode(text='xx'):
    return HttpResponse(str('qrcode'))

但实际上, Django 的要求是第一个参数必须是 HTTP 请求对象 request

因此,正确的做法是

from django.shortcuts import render
from django.http import HttpResponse

# Create your views here.
def gen_qrcode(request, text='xx'):
    return HttpResponse(str('qrcode'))
目前尚无回复
简单教程 = 简单教程,简单编程
简单教程 是一个关于技术和学习的地方
现在注册
已注册用户请 登入
关于   |   FAQ   |   我们的愿景   |   广告投放   |  博客

  简单教程,简单编程 - IT 入门首选站

Copyright © 2013-2022 简单教程 twle.cn All Rights Reserved.