Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django WSGIRequest参数错误_Python_Django_Django Wsgi - Fatal编程技术网

Python Django WSGIRequest参数错误

Python Django WSGIRequest参数错误,python,django,django-wsgi,Python,Django,Django Wsgi,我会明白的 AttributeError(“'WSGIRequest'对象没有属性'args'”) 当我试着打这个电话的时候 GET/sign\u s3/?s3\u object\u type=image/jpeg&s3\u object\u name=default\u name 我错过什么了吗 除了请求之外,我是否还需要包含*args、**kwargs 以下是回溯: response = middleware_method(request, callback, cal

我会明白的
AttributeError(“'WSGIRequest'对象没有属性'args'”)
当我试着打这个电话的时候

GET/sign\u s3/?s3\u object\u type=image/jpeg&s3\u object\u name=default\u name

我错过什么了吗

除了请求之外,我是否还需要包含
*args、**kwargs

以下是回溯:

            response = middleware_method(request, callback, callback_args, callback_kwargs)
            if response:
                break
    if response is None:
        wrapped_callback = self.make_view_atomic(callback)
        try:
            response = wrapped_callback(request, *callback_args, **callback_kwargs) ...
        except Exception as e:
            # If the view raised an exception, run it through exception
            # middleware, and if the exception middleware returns a
            # response, use that. Otherwise, reraise the exception.
            for middleware_method in self._exception_middleware:
                response = middleware_method(request, e)
观点:

@login_required()
def sign_s3(request):
    object_name = request.args.get('s3_object_name') 

HttpRequest
对象没有
args
属性

你应该使用

request.GET.get('s3_object_name')
要获取
s3\u对象\u名称值


Django文档有一个优秀的on
HttpRequest

HttpRequest
对象没有
args
属性

你应该使用

request.GET.get('s3_object_name')
要获取
s3\u对象\u名称值


Django文档在
HttpRequest

上有一个很好的例子,HttpRequest对象具有类似字典的对象id,但没有args属性

如果密钥是必需的且存在于请求对象中,则可以使用:

请求。获取['s3\u对象\u名称']

如果键存在,则返回一个值。如果不是,那么是一个例外

如果您的密钥是可选的:


request.GET.GET('s3\u object\u name')

HttpRequest对象具有类似字典的对象id,但没有args属性

如果密钥是必需的且存在于请求对象中,则可以使用:

请求。获取['s3\u对象\u名称']

如果键存在,则返回一个值。如果不是,那么是一个例外

如果您的密钥是可选的:


request.GET.GET('s3\u object\u name')

,与此错误相同: 除User.DoesNotExist外:属性错误:“function”对象没有属性“DoesNotExist”

class UserPosts(generic.ListView):
   model = models.Post
   template_name = 'posts/user_post_list.html'

def get_queryset(self):
    try:
        self.post_user = User.objects.prefetch_related("posts").get(
            username__iexact=self.kwargs.get("username")
        )
    except User.DoesNotExist:
        raise Http404
    else:
        return self.post_user.posts.all()

def get_context_data(self, **kwargs):
    context = super().get_context_data(**kwargs)
    context["post_user"] = self.post_user
    return context
我可以通过以下方式解决它:

从django.contrib.auth导入get\u user\u模型


User=get\u User\u model() 除User.DoesNotExist外:属性错误:“function”对象没有属性“DoesNotExist”

class UserPosts(generic.ListView):
   model = models.Post
   template_name = 'posts/user_post_list.html'

def get_queryset(self):
    try:
        self.post_user = User.objects.prefetch_related("posts").get(
            username__iexact=self.kwargs.get("username")
        )
    except User.DoesNotExist:
        raise Http404
    else:
        return self.post_user.posts.all()

def get_context_data(self, **kwargs):
    context = super().get_context_data(**kwargs)
    context["post_user"] = self.post_user
    return context
我可以通过以下方式解决它:

从django.contrib.auth导入get\u user\u模型


User=get\u User\u model()

我们应该知道没有回溯会发生什么吗?那不是回溯,那似乎是其他一些随机代码。我们应该知道没有回溯会发生什么吗?那不是回溯,那似乎是其他一些随机代码。是的,就是这样!必须记住。。。文档第一!是的,就是这样!必须记住。。。文档第一!