Sam*_*des 5 query-string x-frame-options django-rest-framework
我正在尝试通过 DRF 进行 GET API 调用。
我的网址如下所示: http://127.0.0.1: 8000/patha/pathb/pathc/pathd/cd7701b?name=IT&size=20&workflow=rv
但它产生了一个错误:
if response.get('X-Frame-Options') is not None:
AttributeError: 'NoneType' object has no attribute 'get'
Run Code Online (Sandbox Code Playgroud)
但是当我只是发送两个查询参数时:
http://127.0.0.1:8000/patha/pathb/pathc/pathd/cd007b?name=IT&size=20
Run Code Online (Sandbox Code Playgroud)
或者,这三个参数中的两个参数的任意组合将到达视图方法。
我的视图方法如下所示:
class MyRtList(generics.ListAPIView, customMixin):
...
# Here I'd like to use all three inputs:
# cd007b
# `name` and `size`
Run Code Online (Sandbox Code Playgroud)
和 urls.py:
url(r'patha/pathb/pathc/(?P<name>[^/]+)?$',views.MyRtList.as_view()),
Run Code Online (Sandbox Code Playgroud)
我正在经历医生。使用 param1 和 param2 显示的示例。最多可以使用两个查询参数吗?是否禁止使用像 cd007b 和查询参数这样的混合数据?因为它会被 3 个参数卡住,但不会被 2 个参数卡住。
哪里出了问题?
这是我的案例的解决方案
如果您忘记将渲染添加到views.py中的视图中,请确保添加render
视图.py
前:
from django.shortcuts import render
# Create your views here.
def test1(request):
kontext = {}
# This will give error
return (request, 'appName/test1.html', kontext)
Run Code Online (Sandbox Code Playgroud)
后:
from django.shortcuts import render
# Create your views here.
def test1(request):
kontext = {}
return render(request, 'appName/test1.html', kontext)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5574 次 |
| 最近记录: |